杭电2103---Family planning

                               Family planning

在草稿箱呆了好几年了,才放出来

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

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
题目要求:本题的大概意思就是求不按规则生娃要交多少罚款?规则有两条:1.不能超生。 2.即使没有超生,但生完男娃后就不能再生啦。(注意第一个男娃是免费的,我由于忽略了这个问题,结果第一次提交wa掉)
c语言代码:( 在草稿箱呆了好几年了,才放出来
#include
int main()
{
int t,m,n,i,a;
scanf("%d",&t);
while(t--)
{
long long int sum=0,ss=10000,l=0,ll=0;   
scanf("%d%d",&m,&n);
for(i=1;i<=n;i++)
{
scanf("%d",&a);
if(ll==0&&i<=m&&a==1)
{
   ll=1;continue;
}
if(i<=m&&ll>0)  l++;               //计算有多少个不和规矩的娃
if(i>m)    l++;                           //这是超生的娃
}
for(i=1;i<=l;i++)                             //计算罚款
{
sum+=ss;
ss*=2;
}
printf("%lld RMB\n",sum);
}
return 0;
}

你可能感兴趣的:(编程题,HDUJ)