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 }
  • 相关阅读:
    【翻译】R 中的设计模式
    CLR 协变、逆变
    设计模式之工厂模式
    c# 浮点数计算问题
    WebAPI参数传值string转bool,int转bool相关问题
    CLR via c# 值类型“不可变”
    C# CLR via 对象内存中堆的存储【类型对象指针、同步块索引】
    c# 关于字段内存排序
    《拖拉一点也无妨》读后感
    .NET CORE 学习笔记之安装EF【Microsoft.EntityFrameworkCore】扩展报错
  • 原文地址:https://www.cnblogs.com/Penn000/p/5777860.html
Copyright © 2011-2022 走看看