HDOJ(HDU) 2103 Family planning(需要注意范围)

简介: HDOJ(HDU) 2103 Family planning(需要注意范围)

Problem Description

As far as we known,there are so many people in this world,expecially in china.But many people like LJ always insist on that more people more power.And he often says he will burn as much babies as he could.Unfortunatly,the president XiaoHu already found LJ’s extreme mind,so he have to publish a policy to control the population from keep on growing.According the fact that there are much more men than women,and some parents are rich and well educated,so the president XiaoHu made a family planning policy:

According to every parents conditions to establish a number M which means that parents can born M children at most.But once borned a boy them can’t born other babies any more.If anyone break the policy will punished for 10000RMB for the first time ,and twice for the next time.For example,if LJ only allowed to born 3 babies at most,but his first baby is a boy ,but he keep on borning another 3 babies, so he will be punished for 70000RMB(10000+20000+40000) totaly.


Input

The first line of the input contains an integer T(1 <= T <= 100) which means the number of test cases.In every case first input two integers M(0<=M<=30) and N(0<=N<=30),N represent the number of babies a couple borned,then in the follow line are N binary numbers,0 represent girl,and 1 represent boy.


Output

Foreach test case you should output the total money a couple have to pay for their babies.


Sample Input

2

2 5

0 0 1 1 1


2 2

0 0


Sample Output

70000 RMB

0 RMB


题目大意:国家要实行计划生育,但是为了照顾到某些家庭希望能生个男孩的愿望,所以总统颁布了一条生育法令。给每个家庭一个生育孩子的限额M,就是表示一个家庭最多能生几个孩子,但是如果一旦生了男孩的话,就不能再生了,即使你还没有达到生育的限额。对于违规的家庭,第一次罚10000,第二次就罚20000,第三次就罚40000,以此类推,就是一个等比数列了,之后罚款都是之前的2倍。现在题目给你限额M和每个家庭实际生了几个孩子N,问你这个家庭一共要罚多少钱。


这个题目坑的地方就是数据的范围。。。。

注意要用long型的,也可以缩小10000倍,最后输出的时候加上“0000”四个0一起输出就可以了。


分成2部分处理,一种情况是m小于等于n的,

这种情况下只要判断生出男孩后,无论男女都要罚款。

另外一种就是m大于n的。

在第一种情况内,还有如果大于n个了,只要大于的都要罚款!!!

import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while(t-->0){
            int n  =sc.nextInt();
            int m  = sc.nextInt();
            int child[] = new int[m];
            for(int i=0;i<m;i++){
                child[i] = sc.nextInt();
            }
            long fine = 0;
            long excess = 1;
            //第一种情况,生下的孩子数量比规定最多的数量要少或者一样
            //则只有在生出男孩之后才能罚款;
            if(m<=n){
                boolean isGirl = true;
                for(int i=0;i<m;i++){
                    if(child[i]==1&&isGirl){
                        isGirl=false;
                        continue;
                    }
                    if(!isGirl){
                        fine+=excess;
                        excess*=2;
                    }
                }
            }else{
                boolean isGirl = true;
                for(int i=0;i<n;i++){
                    if(child[i]==1&&isGirl){
                        isGirl=false;
                        continue;
                    }
                    if(!isGirl){
                        fine+=excess;
                        excess*=2;
                        //System.out.println("!!!fine="+fine+",,"+"excess="+excess);
                    }
                }
                for(int j=n;j<m;j++){
                    fine+=excess;
                    excess*=2;
                    //System.out.println("fine="+fine+",,"+"excess="+excess);
                }
            }
            if(excess==1){
                System.out.println("0 RMB");
            }else{
                System.out.println(fine+"0000 RMB");
            }
        }
    }
}
目录
相关文章
|
6月前
|
Java
HDU-1004—Let the Balloon Rise
HDU-1004—Let the Balloon Rise
28 0
Codeforces Round #192 (Div. 2) (330B) B.Road Construction
要将N个城市全部相连,刚开始以为是最小生成树的问题,其实就是一道简单的题目。 要求两个城市之间不超过两条道路,那么所有的城市应该是连在一个点上的,至于这个点就很好找了,只要找到一个没有和其他点有道路限制的即可。
40 0
ZOJ - Summer 2018 - Contest 2 by Astolfo - Problems - 1002: Hazard and The Triangle
ZOJ - Summer 2018 - Contest 2 by Astolfo - Problems - 1002: Hazard and The Triangle
106 0
ZOJ - Summer 2018 - Contest 2 by Astolfo - Problems - 1002: Hazard and The Triangle
HDOJ(HDU) 1673 Optimal Parking
HDOJ(HDU) 1673 Optimal Parking
122 0
|
Java 文件存储
HDOJ(HDU) 2132 An easy problem
HDOJ(HDU) 2132 An easy problem
105 0
|
Java 文件存储
HDOJ(HDU) 2123 An easy problem(简单题...)
HDOJ(HDU) 2123 An easy problem(简单题...)
167 0
|
Java
HDOJ(HDU) 2164 Rock, Paper, or Scissors?
HDOJ(HDU) 2164 Rock, Paper, or Scissors?
114 0
|
数据挖掘
HDOJ 1032(POJ 1207) The 3n + 1 problem
HDOJ 1032(POJ 1207) The 3n + 1 problem
128 0