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

    ILayer http://127.0.0.1:47873/help/1-4452/ms.help?method=page&id=ESRICARTO-7E8C676F-000BCF&p ...

  2. 【HighCharts系列教程】九、语言属性——Lang

    一.lang属性说明 Lang属性主要用于配置显示的文字等语言相关属性. 主要可配置如下内容:小数点符号.导出相关文字.月份文字.星期文字等 lang属性不重要,无特殊情况,不用配置. 二.lang属 ...

  3. SQL truncate 、delete与drop区别

    SQL truncate .delete与drop区别 相同点: 1.truncate和不带where子句的delete.以及drop都会删除表内的数据. 2.drop.truncate都是DDL语句 ...

  4. (简单) POJ 1321 棋盘问题,回溯。

    Description 在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别.要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘,摆放k个棋子 ...

  5. Mysql 常用引擎的特点及选择使用策略

    Mysql 常用引擎的特点及选择使用策略 Mysql数据库常用存储引擎 Mysql数据库是一款开源的数据库,支持多种存储引擎的选择,比如目前最常用的存储引擎有:MyISAM,InnoDB,Memory ...

  6. Leetcode题1

    Given an array of integers, find two numbers such that they add up to a specific target number. The ...

  7. iOS第三方常用类库

    1.AFNetworking AFNetworking 采用 NSURLConnection + NSOperation, 主要方便与服务端 API 进行数据交换, 操作简单, 功能强大, 现在许多人 ...

  8. ANSI标准

    NSI:美国国家标准学会(AMERICAN NATIONAL STANDARDS INSTITUTE: ANSI)成立于1918年.当时,美国的许多企业和专业技术团体,已开始了标准化工作,但因彼此间没 ...

  9. NLPIR中文分词器的使用

    一.普通java项目 (1)添加项目jar包 File -> Project Structure     Libarries 添加jar包jna-4.0.0.jar (2)将Data文件夹复制到 ...

  10. java 获取指定日期

    //可以设置指定那一天:例如,最近一周,参数传入-7,最近一月,参数传入-30...private String getBeginDate(int date) throws ParseExceptio ...