您的位置:首页 > 其它

Family planning

2015-10-28 20:27 316 查看


Family planning

Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 8806 Accepted Submission(s): 2283



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


题目:一个计划生育方案:每对夫妻最多生n个孩子,超生的要罚款,但是在这n个孩子里,如果生了男孩,就不能再生了,否则超生的也要罚款。罚款的数额和超生个数有关,超生第一个罚款10000元,超生第二个20000元,超生第三个40000元,每次都是上一个的2倍。现在给你多组数据,求各组需要交的罚款。

提醒:在允许生的孩子个数内找是否已生男孩,在进行计算。因为罚款数据较大,可输出字符串“0000
RMB”,当结果为0是则不用输出。

#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int T,n,m,k,i,sum,num;
int a[100];
cin>>T;
while(T--)
{
cin>>n>>m;
for(i=0;i<m;i++)
cin>>a[i];
k=0;
for(i=0;i<n;i++)
{
k+=1;
if(a[i]==1)break;
}
sum=0;num=1;
for(i=0;i<m-k;i++)
{
sum+=num;
num*=2;
//或者改为   sum+=pow(2,i);
}
if(sum==0)cout<<"0 RMB"<<endl;
else cout<<sum<<"0000 RMB"<<endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: