博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDOJ(HDU) 2103 Family planning(需要注意范围)
阅读量:6097 次
发布时间:2019-06-20

本文共 2161 字,大约阅读时间需要 7 分钟。

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

题目大意:国家要实行计划生育,但是为了照顾到某些家庭希望能生个男孩的愿望,所以总统颁布了一条生育法令。给每个家庭一个生育孩子的限额M,就是表示一个家庭最多能生几个孩子,但是如果一旦生了男孩的话,就不能再生了,即使你还没有达到生育的限额。对于违规的家庭,第一次罚10000,第二次就罚20000,第三次就罚40000,以此类推,就是一个等比数列了,之后罚款都是之前的2倍。现在题目给你限额M和每个家庭实际生了几个孩子N,问你这个家庭一共要罚多少钱。

这个题目坑的地方就是数据的范围。。。。

注意要用long型的,也可以缩小10000倍,最后输出的时候加上“0000”四个0一起输出就可以了。

分成2部分处理,一种情况是m小于等于n的,

这种情况下只要判断生出男孩后,无论男女都要罚款。
另外一种就是m大于n的。
在第一种情况内,还有如果大于n个了,只要大于的都要罚款!!!

import java.util.Scanner;public class Main{    public static void main(String[] args) {        Scanner sc = new Scanner(System.in);        int t = sc.nextInt();        while(t-->0){            int n  =sc.nextInt();            int m  = sc.nextInt();            int child[] = new int[m];            for(int i=0;i

转载地址:http://sgwza.baihongyu.com/

你可能感兴趣的文章
ICCV2017 论文浏览记录
查看>>
科技巨头的交通争夺战
查看>>
当中兴安卓手机遇上农行音频通用K宝 -- 卡在“正在通讯”,一直加载中
查看>>
Shell基础之-正则表达式
查看>>
JavaScript异步之Generator、async、await
查看>>
讲讲吸顶效果与react-sticky
查看>>
c++面向对象的一些问题1 0
查看>>
直播视频流技术名词
查看>>
iOS13-适配夜间模式/深色外观(Dark Mode)
查看>>
网易跟贴这么火,背后的某个力量不可忽视
查看>>
品友互动受邀2018商汤人工智能峰会
查看>>
企业级java springboot b2bc商城系统开源源码二次开发-hystrix参数详解(八)
查看>>
java B2B2C 多租户电子商城系统- 整合企业架构的技术点
查看>>
IOC —— AOP
查看>>
比特币现金将出新招,推动比特币现金使用
查看>>
数据库的这些性能优化,你做了吗?
查看>>
某大型网站迁移总结(完结)
查看>>
mysql的innodb中事务日志(redo log)ib_logfile
查看>>
部署SSL证书后,网页内容造成页面错误提示的处理办法
查看>>
MS SQLSERVER通用存储过程分页
查看>>