码迷,mamicode.com
首页 > 其他好文 > 详细

HDU 2103 Family planning

时间:2018-08-03 00:55:35      阅读:166      评论:0      收藏:0      [点我收藏+]

标签:ready   php   NPU   scanf   esc   wing   temp   mos   ane   

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

 

Problem Description
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.
 
Input
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.
 
Output
Foreach test case you should output the total money a couple have to pay for their babies.
 
Sample Input
2
2 5
0 0 1 1 1
2 2
0 0
 
Sample Output
70000 RMB
0 RMB
 
代码:
#include <bits/stdc++.h>
using namespace std;

int a[50];

int main() {
    int T;
    scanf("%d", &T);
    for(int i = 1; i <= T; i ++) {
        int temp = 0;
        int n, m, k;
        scanf("%d%d", &m, &n);
        double sum = 0;
        for(int j = 1; j <= n; j ++)
            scanf("%d", &a[j]);

        for(int j = 1; j <= n; j ++) {
            if(a[j] == 1) {
                temp = j;
                break;
            }
        }

        if(n <= m) {
            if(temp == 0 || temp == n) {
                printf("0 RMB\n");
                continue;
            }
            else
                k = n - temp - 1;
        }
        else {
            if(temp == 0)
                k = n - m - 1;
            else {
                if(temp > m)
                    k = n - m - 1;
                else
                    k = n - temp -1;
            }
        }

        for(int j = 0; j <= k; j ++)
            sum += pow(2.0, j  * 1.0);
        sum = sum * 10000;
        printf("%.0lf RMB\n", sum);
    }
    return 0;
}

  

HDU 2103 Family planning

标签:ready   php   NPU   scanf   esc   wing   temp   mos   ane   

原文地址:https://www.cnblogs.com/zlrrrr/p/9410878.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!