Family planning
Time Limit: 3000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 5926 accepted submission (s): 1521
Problem descriptionas far as we known, there are so popular people in this world, expecially in China. but every people like LJ always insist on that more people more power. and he often says he will burn as much babies as he cocould. 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 processing RMB 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 shoshould output the total money a couple have to pay for their babies.
Sample Input
22 50 0 1 1 12 20 0
Sample output
70000 RMB0 RMB
Sourcehdu 2007-6 Programming Contest
Recommendxhd is a relatively watery question. In the end, I want to try it out for half an hour. I didn't expect this question to be A, and I saw how others did it, why is the AC rate not very high for this question? I have read that most children's shoes use _ int64, which is actually not needed because up to 30 bits and 2 ^ 30 are still within the int range, this is clear, so you can simply add four zeros to the result. You don't need to use other things, and you don't need to use arrays to store anything, as long as the demarcation points are found, all the other points will be fined. Note that abnormal test data cannot be generated!
#include <iostream>#include <string.h>#include <stdio.h>using namespace std;int main(){int n,m,k;bool flag;int num;int t,i;int ans;scanf("%d",&t);while(t--){ans=0;num=1;scanf("%d%d",&m,&n);flag=1;if(m==0)flag=0;for(i=0;i<n;i++){scanf("%d",&k);if(flag){if(k==1 || i==m-1)flag=0;}else{ans+=num;num*=2;}}if(ans>0)printf("%d0000 RMB\n",ans);elseprintf("0 RMB\n");}return 0;}