您的位置:首页 > 编程语言 > Java开发

hdu 2103 java 细节题

2016-01-15 17:33 155 查看
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");

}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: