Family planning

Family planning

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

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
计算机学院ACM大学生程序设计竞赛(2007’6)           http://acm.hdu.edu.cn/showproblem.php?pid=2103

对于这一题,实在是让人很无语,本来是一道很简单的题目,却让我WA了七次。这一题最大的一个特点是:并不是它很难,而是杭电的OJ和福大的OJ不一样,处理64位整型的时候,定义为long long型,福大的可以通过,而杭电的的却不行,本来想用大数去求解的,可实在是太麻烦。后来改了一下,就可以了,定义的时候改成:__int64,输出的时候用:printf(“%I64d”)就可以了。

这一题其实后来想了一下,还有一种方法,可以不要用到64位,用32位的就可以了,因为每一次都是乘以2,最多三十次,也就是最多不超过2^32,而初始值是10000,就是说每一次用初始值乘以2,所以最终的结果一定会有四个0,是可以用来直接输出的,而如果把这40参加运算,就一定要用到64位才够,而如果不让这40参加运算,就只要32位就够了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值