zoukankan      html  css  js  c++  java
  • HDU5835

    Danganronpa

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
    Total Submission(s): 570    Accepted Submission(s): 414

    Problem Description

    Chisa Yukizome works as a teacher in the school. She prepares many gifts, which consist of n kinds with a[i] quantities of each kind, for her students and wants to hold a class meeting. Because of the busy work, she gives her gifts to the monitor, Chiaki Nanami. Due to the strange design of the school, the students' desks are in a row. Chiaki Nanami wants to arrange gifts like this:

    1. Each table will be prepared for a mysterious gift and an ordinary gift.

    2. In order to reflect the Chisa Yukizome's generosity, the kinds of the ordinary gift on the adjacent table must be different.

    3. There are no limits for the mysterious gift.

    4. The gift must be placed continuously.

    She wants to know how many students can get gifts in accordance with her idea at most (Suppose the number of students are infinite). As the most important people of her, you are easy to solve it, aren't you?
     

    Input

    The first line of input contains an integer T(T10) indicating the number of test cases.

    Each case contains one integer n. The next line contains n (1n10) numbers: a1,a2,...,an(1ai100000).
     

    Output

    For each test case, output one line containing “Case #x: y” (without quotes) , where x is the test case number (starting from 1) and y is the answer of Chiaki Nanami's question.
     

    Sample Input

    1
    2
    3 2
     

    Sample Output

    Case #1: 2
     
    题意:有n种礼物,每个有ai个,现在开始给每个人发礼物,每人一个普通礼物和神秘礼物,相邻两人的普通礼物必须不同,每个礼物都可以作为神秘礼物/普通礼物,问最多可以发给多少人。
    ans不会超过礼物总数的一半,令其中个数最多的礼物数目为mx,则mx足够多时,ans为sum-mx个其他礼物,中间穿插sum-mx+1个mx礼物,共有2*(sum-mx)+1人,否则为sum/2人。
     1 //2016.8.16
     2 #include<iostream>
     3 #include<cstdio>
     4 #include<algorithm>
     5 
     6 using namespace std;
     7 
     8 int a[15];
     9 
    10 int main()
    11 {
    12     int T, n, kase = 0, sum, mx, ans;
    13     cin>>T;
    14     while(T--)
    15     {
    16         sum = mx = 0;
    17         scanf("%d", &n);
    18         for(int i = 0; i < n; i++)
    19         {
    20             scanf("%d", &a[i]);
    21             sum += a[i];
    22             if(mx<a[i])mx = a[i];
    23         }
    24         printf("Case #%d: ", ++kase);
    25         ans = min(sum/2, 2*(sum-mx)+1);
    26         printf("%d
    ", ans);
    27     }
    28 
    29     return 0;
    30 }
  • 相关阅读:
    phpstorm+Xdebug断点调试PHP
    解决PHP curl https时error 77(Problem with reading the SSL CA cert (path? access rights?))
    Windows下安装并设置Redis
    PHP使用数据库的并发问题
    PHP 数组排序
    js 异常处理
    nginx php上传大文件的设置(php-fpm)
    第二章 基本数据类型:常见数据类型的方法
    第一章 python介绍、变量、数据类型、流程控制语句等
    python2.x和python3.x的区别
  • 原文地址:https://www.cnblogs.com/Penn000/p/5777860.html
Copyright © 2011-2022 走看看