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;
}
整体思路就是找到罚款的人数。
罚款的条件有二:
1.生的小孩大于规定的小孩数
2.生了男孩之后,就禁止生小孩。
if (num[0] <= n)
{
k = num[1];
}
比如我只能生4个小孩。于是我生了
1 0 0 0 一男孩,3女孩
按照你的逻辑mum[0]<4
k = num[1]=1
然而违规的小孩有三个,分别是三个女孩(生男孩之后不可以再生小孩)
k应该等于3.
额,好吧,我以为不考虑生孩子的顺序,而是怎么罚款最少怎么来。
请把题目也贴出来,同时代码放到代码块里
– Shendu.cc 6年前