# 可以帮我看看问题出在哪儿吗？E - Family planning 的题，感觉我的代码还算逻辑比较清楚了。

0

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.

InputThe 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.OutputForeach test case you should output the total money a couple have to pay for their babies.

Sample Input2

2 5

0 0 1 1 1

2 2

0 0

Sample Output

70000 RMB

0 RMB

#include<stdio.h>

int main()
{
int nn[31];
nn[0] = 1;
for (int i = 1; i < 31; i++)
{
nn[i] = nn[i - 1] * 2;
}
int datanum;
scanf("%d", &datanum);
while (datanum--)
{
int num[2] = { 0 };
int n, m,num1,sum;
scanf("%d%d", &n, &m);
for (int i = 0; i < m; i++)
{
scanf("%d", &num1);
num[num1]++;
}
int k;
if (num[0] <= n)
{
k = num[1];
}
else
{
k = num[0] + num[1] - n;
}
sum = nn[k] - 1;
if (sum == 0)
{
printf("0 RMB\n");
}
else
{
printf("%d0000 RMB\n",sum);
}
}
return 0;
}

Shendu.cc 3年前

0

1.生的小孩大于规定的小孩数

2.生了男孩之后，就禁止生小孩。

if (num[0] <= n)
{
k = num[1];
}

1 0 0 0   一男孩，3女孩

k = num[1]=1

k应该等于3.

Shendu.CC | 小虾三级 |园豆：1918 | 2018-04-05 17:57

您需要登录以后才能回答，未注册用户请先注册