首页 新闻 搜索 专区 学院

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

0
悬赏园豆:5 [已解决问题] 解决于 2018-04-06 10:16
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;
}

 

整体思路就是找到罚款的人数。

神韵袖藏的主页 神韵袖藏 | 初学一级 | 园豆:188
提问于:2018-04-05 11:55

请把题目也贴出来,同时代码放到代码块里

Shendu.cc 2年前
< >
分享
最佳答案
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.

收获园豆:5
Shendu.CC | 小虾三级 |园豆:1914 | 2018-04-05 17:57

额,好吧,我以为不考虑生孩子的顺序,而是怎么罚款最少怎么来。

神韵袖藏 | 园豆:188 (初学一级) | 2018-04-06 10:15
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册