hdu 2103 java 细节题

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 m=sc.nextInt();//允许生小孩的数目
int n=sc.nextInt();//实际生小孩数
int child[]=new int[n+1];//孩子的是男是女
long sumPay=0;//罚款总数
long count=0,num=1;//count记录孩子数,num罚款倍数//注意为long型
boolean isBoy=false;
for(int i=1;i<child.length;i++){
child[i]=sc.nextInt();
}
if(n<=m){//没有超生的情况下
for(int i=1;i<child.length;i++){
if(child[i]==1){
isBoy=true;
count=i;
break;
}
}
if(isBoy&&count!=n){//所生男孩在允许生小孩的数目之前
while(n-count>0){
sumPay+=10000*num;
num*=2;
count++;
}
}
}else{//超生的情况下
for(int i=1;i<m+1;i++){
if(child[i]==1){
isBoy=true;
count=i;
break;
}
}
if(isBoy&&count<m){//所生男孩在允许生小孩的数目之前,罚款从男孩后开始记录
while(n-count>0){
sumPay+=10000*num;
num*=2;
count++;
}
}else{
while(n-m>0){//所生男孩在允许生小孩的数目之后或者在允许生小孩数之前没有男孩,罚款从允许生小孩开始记录后开始记录
sumPay+=10000*num;
num*=2;
m++;
}
}
}
System.out.println(sumPay+" RMB");
}
}


}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值