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(T≤10) indicating the number of test cases.

Each case contains one integer n. The next line contains n (1≤n≤10) numbers: a1,a2,...,an, (1≤ai≤100000).

 

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人。
 //2016.8.16
#include<iostream>
#include<cstdio>
#include<algorithm> using namespace std; int a[]; int main()
{
int T, n, kase = , sum, mx, ans;
cin>>T;
while(T--)
{
sum = mx = ;
scanf("%d", &n);
for(int i = ; i < n; i++)
{
scanf("%d", &a[i]);
sum += a[i];
if(mx<a[i])mx = a[i];
}
printf("Case #%d: ", ++kase);
ans = min(sum/, *(sum-mx)+);
printf("%d\n", ans);
} return ;
}

HDU5835的更多相关文章

随机推荐

  1. javascript 中this的使用场景全

    1. global this 2.function this 3.prototype this 4. object this 5.DOM this 6 HTML this 7 override thi ...

  2. 在线演示红黑树(javascript)

    在线演示地址:http://sandbox.runjs.cn/show/2nngvn8w 有点遗憾,本想实现个很棒的功能,就是红黑树每次“变形”的时候,做个“快照”,“变形”了几次就“快照”几次.方便 ...

  3. 如何高效的用判断用js判断ie6

    用js判断ie6的方法有很多,如: 1. var isIE=!!window.ActiveXObject; var isIE6=isIE&&!window.XMLHttpRequest ...

  4. Hibernate---O/R Mapping

    1. JDBC数据库繁琐 2. sql语句不是面向对象 3. 可以在对象和关系表之间建立关联简化编程 4. O/R Mapping可以简化编程, 跨越数据库平台 比较流行的O/R Mapping Fr ...

  5. CodeForces 617C Watering Flowers

    无脑暴力题,算出所有点到圆心p1的距离的平方,从小到大排序. 然后暴力枚举p1的半径的平方,计算剩余点中到p2的最大距离的平方,枚举过程中记录答案 #include<cstdio> #in ...

  6. Eclipse JDK的安装

    1.jdk安装无法配置,eclipse绿色版安装无法打开,系统的版本问题(32位和64位): 2.Eclipse下载PDT时,可以如下安装: 三个地方设置好即可,其实第三个选第一个的话会出现无法提供函 ...

  7. iOS推送跳转AppDelegate跳转VC

    在开发项目中,会有这样变态的需求: 推送:根据服务端推送过来的数据规则,跳转到对应的控制器 feeds列表:不同类似的cell,可能跳转不同的控制器(嘘!产品经理是这样要求:我也不确定会跳转哪个界面哦 ...

  8. 适用于SQl数据的Sql语句

    ---基础知识if exists(select * from sysdatabases where name='Exam') ---判断数据库中是否存在该数据库drop database Examgo ...

  9. SD卡兼容性问题(转)

    看到一篇关于硬件抗干扰的应用实例,很有参考值.所以,转过来方便查找. 源文:SD卡兼容性问题 最近碰到了一个SD卡兼容性的问题.主芯片SD卡组的信号,经过转接板,长排线,然后再到SD卡子板之后.对多种 ...

  10. 步进控件——UIStepper

    步进控件,可用于替换传统用于输入值的文本框.步进控件提供了“+”和“-”两个按钮,用来改变stepper内部value的增加或减少,调用的事件是UIControlEventValueChanged.由 ...