hdu 2103 Family planning

来源:互联网 发布:淘宝会员名大全5个字 编辑:程序博客网 时间:2024/05/22 16:11

Family planning

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


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
22 50 0 1 1 12 20 0
 

Sample Output
70000 RMB0 RMB
 
这道题说明了  男生的质量是高于女孩的质量的大笑

#include <iostream>#include <stdio.h>#include <stdlib.h>#include <math.h>using namespace std;int main(){    int n;    int N,M,i;    cin>>n;    int a[32];        int count;  记录    int j;    while (n--)    {        count=0;    //记录扫描的孩子个数        j=0;       //罚款孩子个数        a[0]=0;    // 存罚款的        cin>>M>>N;        if(N==0)        {            cout<<"0"<<" "<<"RMB"<<endl;                    }        else        {            for (i=1; i<=N; i++)            {                cin>>a[i];                if(M==0)                {                    a[0]+=10000*pow(2,i-1);                }                else                {                    if(count<M)                    {                        if(a[i]==0)                        {                            count++;                            continue;                        }                        else                        {                            count=M;   //发现生了男孩  后面继续生就要罚款 相当与达到了最大能生得数量                        }                    }                    else                    {                        a[0]+=10000*pow(2,j++);                    }                }            }            cout<<a[0]<<" "<<"RMB"<<endl;        }            }        return 0;}


0 0
原创粉丝点击