首页 > 代码库 > HDU2103 Family planning【水题】

HDU2103 Family planning【水题】

Family planning


Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 7891    Accepted Submission(s): 2042

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
 
Source

HDU 2007-6 Programming Contest


题目大意:小虎发明了一个计划生育方案:每对夫妇最多生M个孩子,超生的要罚款,但是

在这M个孩子里,如果生了男孩,就不能再生了,否则超生的也要罚款。罚款的数额和超生

个数有关,超生一个罚款10000元,超生第二个20000元,超生第三个40000元,每次都是

上一个的2倍。现在给你一对父母生的孩子个数N和最多生孩子个数M,以及N个孩子的性别。

求:她们要交多少钱的罚款。

思路:先求M个孩子里有木有男孩,有的话,从下一个孩子开始算超生的罚款,没有的话,就

从第M+1个孩子开始计算罚款。计算罚款的时候先按1、2、4元计算,输出的时候,在输出字

符串"0000",这样避免了数据溢出,注意答案为0的时候,不必再输出字符串。


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;

int a[33];
int main()
{
    int T;
    cin >> T;
    while(T--)
    {
        int N,M;
        cin >> M >> N;
        for(int i = 0; i < N; ++i)
            cin >> a[i];
        int ans = 0,pos = -1,Num;
        for(int i = 0; i < M; ++i)
            if(a[i] == 1)
            {
                pos = i;
                break;
            }

        if(pos != -1)
        {
            Num = 1;
            for(int i = pos+1; i < N; ++i)
            {
                ans += Num;
                Num *= 2;
            }
        }
        else
        {
            Num = 1;
            for(int i = M; i < N; ++i)
            {
                ans += Num;
                Num *= 2;
            }
        }
        if(ans != 0)
            cout << ans << "0000 RMB" << endl;
        else
            cout << "0 RMB" << endl;
    }

    return 0;
}


HDU2103 Family planning【水题】