HDOJ(HDU) 2103 Family planning(需要注意范围)
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<m;i++){
child[i] = sc.nextInt();
}
long fine = 0;
long excess = 1;
//第一种情况,生下的孩子数量比规定最多的数量要少或者一样
//则只有在生出男孩之后才能罚款;
if(m<=n){
boolean isGirl = true;
for(int i=0;i<m;i++){
if(child[i]==1&&isGirl){
isGirl=false;
continue;
}
if(!isGirl){
fine+=excess;
excess*=2;
}
}
}else{
boolean isGirl = true;
for(int i=0;i<n;i++){
if(child[i]==1&&isGirl){
isGirl=false;
continue;
}
if(!isGirl){
fine+=excess;
excess*=2;
//System.out.println("!!!fine="+fine+",,"+"excess="+excess);
}
}
for(int j=n;j<m;j++){
fine+=excess;
excess*=2;
//System.out.println("fine="+fine+",,"+"excess="+excess);
}
}
if(excess==1){
System.out.println("0 RMB");
}else{
System.out.println(fine+"0000 RMB");
}
}
}
}
HDOJ(HDU) 2103 Family planning(需要注意范围)的更多相关文章
- HDU 2103 Family planning
http://acm.hdu.edu.cn/showproblem.php?pid=2103 Problem Description As far as we known,there are so m ...
- 【HDOJ】2103 Family planning
题目挺有意思.虽然不是很难. #include <stdio.h> int main() { unsigned int m, n, case_n; unsigned ; scanf(&qu ...
- HDU 2103 Family Plan
题目HDU 2103:http://acm.hdu.edu.cn/showproblem.php?pid=2103 Problem Description As far as we known,the ...
- HDOJ(HDU).1412 {A} + {B} (STL SET)
HDOJ(HDU).1412 {A} + {B} (STL SET) 点我挑战题目 题意分析 大水题,会了set直接用set即可. 利用的是set的互异性(同一元素有且仅有一项). #include ...
- HDOJ(HDU).1754 I Hate It (ST 单点替换 区间最大值)
HDOJ(HDU).1754 I Hate It (ST 单点替换 区间最大值) 点我挑战题目 题意分析 从题目中可以看出是大数据的输入,和大量询问.基本操作有: 1.Q(i,j)代表求区间max(a ...
- HDOJ(HDU).1166 敌兵布阵 (ST 单点更新 区间求和)
HDOJ(HDU).1166 敌兵布阵 (ST 单点更新 区间求和) 点我挑战题目 题意分析 根据数据范围和询问次数的规模,应该不难看出是个数据结构题目,题目比较裸.题中包括以下命令: 1.Add(i ...
- HDOJ(HDU).2844 Coins (DP 多重背包+二进制优化)
HDOJ(HDU).2844 Coins (DP 多重背包+二进制优化) 题意分析 先把每种硬币按照二进制拆分好,然后做01背包即可.需要注意的是本题只需要求解可以凑出几种金钱的价格,而不需要输出种数 ...
- HDOJ(HDU).1059 Dividing(DP 多重背包+二进制优化)
HDOJ(HDU).1059 Dividing(DP 多重背包+二进制优化) 题意分析 给出一系列的石头的数量,然后问石头能否被平分成为价值相等的2份.首先可以确定的是如果石头的价值总和为奇数的话,那 ...
- HDOJ(HDU).2191. 悼念512汶川大地震遇难同胞――珍惜现在,感恩生活 (DP 多重背包+二进制优化)
HDOJ(HDU).2191. 悼念512汶川大地震遇难同胞――珍惜现在,感恩生活 (DP 多重背包+二进制优化) 题意分析 首先C表示测试数据的组数,然后给出经费的金额和大米的种类.接着是每袋大米的 ...
随机推荐
- Java程序员也应该知道的系统知识系列之(网卡,cpu,内存,硬盘,虚拟化)
https://yq.aliyun.com/articles/1718?spm=5176.100240.searchblog.16.UaGd04 https://yq.aliyun.com/artic ...
- Change value of string array at debug eclipse--转
Question: I have an application, but to test something, I need to change value of a String[]. But wh ...
- iOS 独立开发记录(上)
个月前,完成了个人App的2.0版本,也在普天同庆的六一儿童节这天上架了.因为是个人开发,很多实现都是边探索边做.现在完成之后再回顾,发现自己走了些弯路.所以写了这篇总结,概览了从想法.设计.开发到最 ...
- Android(java)学习笔记241:多媒体之 MediaPlayer使用
MediaPlayer类可用于控制音频/视频文件或流的播放.关于如何使用这个类的方法还可以阅读VideoView类的文档. 1.MediaPlayer 状态图 对播放音频/视频文件和流的控 ...
- java中-静态代码块、构造代码块、构造方法的联系
例如该题: 1 class Fu{ static { System.out.println("这是父类静态代码块"); } { System.out.println("这 ...
- BestCoder冠军赛 - 1009 Exploration 【Tarjan+并查集缩点】
[题意] 给一个图,这个图中既有有向边,又有无向边,每条边只能走一次,问图中是否存在环. 最多10^6个点,10^6个无向边,10^6个有向边 [题解] 因为既有有向边又有无向边,所以不能单纯的用ta ...
- Python之路,Day20 - 分布式监控系统开发
Python之路,Day20 - 分布式监控系统开发 本节内容 为什么要做监控? 常用监控系统设计讨论 监控系统架构设计 监控表结构设计 为什么要做监控? –熟悉IT监控系统的设计原理 –开发一个 ...
- Ajax请求传递参数遇到的问题
想写个同类型的,代码未测. 什么是WebAPI?我的理解是WebAPI+JQuery(前端)基本上能完成Web MVC的功能,即:这么理解吧,WebAPI相当于Web MVC的后台部分. 接下来直接上 ...
- 阿里云OSS存储开发(一)
Step 1. 初始化一个OSSClient OSSClient是与OSS服务交互的客户端,SDK的OSS操作都是通过OSSClient完成的. 下面代码新建了一个OSSClient: using A ...
- 关于User Defined Runtime Attributes的小技巧
在用XIB里自定制view,button,label...的一些属性时,例如边框宽度,边框颜色等,如下图: