首页 > ACM题库 > HDU-杭电 > hdu 2103 Family planning[解题报告]C++
2013
12-29

hdu 2103 Family planning[解题报告]C++

Family planning

问题描述 :

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.

输入:

The 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.

输出:

The 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.

样例输入:

2
2 5
0 0 1 1 1

2 2
0 0

样例输出:

70000 RMB
0 RMB

http://acm.hdu.edu.cn/showproblem.php?pid=2103

bs这道题,我坚信生男生女都一样!

ps:不提前把几个0打出来的话要用__int64,否则会超范围

#include <stdio.h>

int main()
{
    int t,m,n;
    int i;
    int bb,cnt,f;
    __int64 ans,fj;
    scanf("%d",&t);
    while(t--)
    {
        cnt=ans=f=0;
        fj=10000;
        scanf("%d%d",&m,&n);
        for(i=0;i<n;i++)
        {
            scanf("%d",&bb);
            if(cnt==m||f)
            {
                ans+=fj;
                fj<<=1;
            }
            else
            {
                if(bb)
                    f=1;
                else
                    cnt++;
            }
        }
        printf("%I64d RMB\n",ans);
    }
    return 0;
}

 

解题转自:http://www.cnblogs.com/xiaohongmao/archive/2012/04/24/2468853.html


  1. 我一朋友找了个女朋友是外地的,第一次带到家里玩,白天两人出去到山上玩了。晚上回来不对劲了,和这个情况差不多,我也去看了。你们猜怎么着?她竟然我我们的家乡话!要知道她是南方人 普通话都咬舌头呢,怎么会我们这的方言???折腾了一晚上。

  2. 我一朋友找了个女朋友是外地的,第一次带到家里玩,白天两人出去到山上玩了。晚上回来不对劲了,和这个情况差不多,我也去看了。你们猜怎么着?她竟然我我们的家乡话!要知道她是南方人 普通话都咬舌头呢,怎么会我们这的方言???折腾了一晚上。

  3. 我一朋友找了个女朋友是外地的,第一次带到家里玩,白天两人出去到山上玩了。晚上回来不对劲了,和这个情况差不多,我也去看了。你们猜怎么着?她竟然我我们的家乡话!要知道她是南方人 普通话都咬舌头呢,怎么会我们这的方言???折腾了一晚上。

  4. 我一朋友找了个女朋友是外地的,第一次带到家里玩,白天两人出去到山上玩了。晚上回来不对劲了,和这个情况差不多,我也去看了。你们猜怎么着?她竟然我我们的家乡话!要知道她是南方人 普通话都咬舌头呢,怎么会我们这的方言???折腾了一晚上。

  5. 我一朋友找了个女朋友是外地的,第一次带到家里玩,白天两人出去到山上玩了。晚上回来不对劲了,和这个情况差不多,我也去看了。你们猜怎么着?她竟然我我们的家乡话!要知道她是南方人 普通话都咬舌头呢,怎么会我们这的方言???折腾了一晚上。

  6. 我一朋友找了个女朋友是外地的,第一次带到家里玩,白天两人出去到山上玩了。晚上回来不对劲了,和这个情况差不多,我也去看了。你们猜怎么着?她竟然我我们的家乡话!要知道她是南方人 普通话都咬舌头呢,怎么会我们这的方言???折腾了一晚上。

  7. 约瑟夫也用说这么长……很成熟的一个问题了,分治的方法解起来o(n)就可以了,有兴趣可以看看具体数学的第一章,关于约瑟夫问题推导出了一系列的结论,很漂亮

  8. 网站做得很好看,内容也多,全。前段时间在博客园里看到有人说:网页的好坏看字体。觉得微软雅黑的字体很好看,然后现在这个网站也用的这个字体!nice!

  9. Hello Web Admin, I noticed that your On-Page SEO is is missing a few factors, for one you do not use all three H tags in your post, also I notice that you are not using bold or italics properly in your SEO optimization. On-Page SEO means more now than ever since the new Google update: Panda. No longer are backlinks and simply pinging or sending out a RSS feed the key to getting Google PageRank or Alexa Rankings, You now NEED On-Page SEO. So what is good On-Page SEO?First your keyword must appear in the title.Then it must appear in the URL.You have to optimize your keyword and make sure that it has a nice keyword density of 3-5% in your article with relevant LSI (Latent Semantic Indexing). Then you should spread all H1,H2,H3 tags in your article.Your Keyword should appear in your first paragraph and in the last sentence of the page. You should have relevant usage of Bold and italics of your keyword.There should be one internal link to a page on your blog and you should have one image with an alt tag that has your keyword….wait there's even more Now what if i told you there was a simple WordPress plugin that does all the On-Page SEO, and automatically for you? That's right AUTOMATICALLY, just watch this 4minute video for more information at.

  10. 有限自动机在ACM中是必须掌握的算法,实际上在面试当中几乎不可能让你单独的去实现这个算法,如果有题目要用到有限自动机来降低时间复杂度,那么这种面试题应该属于很难的级别了。