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; }
相关文章推荐
- 树莓派Ekho实现中文语音合成
- 中国大学MOOC-陈越、何钦铭-数据结构 排序(堆排序)
- 【随笔】#与 ##的使用含义与区别
- Tomcat内存溢出
- 为你解析神奇的数据库基本用法
- win10无法新建文件夹怎么办 win10右键新建菜单设置方法
- NYOJ 1112 求次数(map)
- poj 1127 Jack Straws 几何 + 弗洛伊德
- Java工具类之Apache的Commons Lang和BeanUtils
- 分布式消息队列XXL-MQ
- 博客已迁移至gzxultra.github.io
- 登陆器列表
- Android数据访问(一)——Asserts
- 七个对我最好的职业建议(精简版)
- java强制类型转换
- STL树
- CodeForces 261C Maxim and Matrix [规律题]
- ios开发系列之页面跳转
- JS中通过建立类来防止方法重载
- 匈牙利算法详解