Danganronpa
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
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:

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

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

There are no limits for the mysterious gift.

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?

传送门:HDU5835

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
1 
2
3 2

Sample Output

1
Case #1: 2

题解

具体做法:维护一个队列 首先可以知道答案不超过所有礼物之和的二分之一(重要!!!),那么通过一个队列来模拟发礼物的过程,将每个礼物的个数放入队列,然后弹出一个判断两个条件:1.如果大于1就减去1然后放入队列尾部,然后将结果加一。2.队列里是否还有下一个元素,也就是要满足题目中不同礼物相隔这个条件。 最后判断如果结果大于所有礼物之和的二分之一,那说明每一个人都能按题意拿到普通礼物,剩下的就都是神秘礼物就可以了。
## AC code:(不包含输入类)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import java.io.*;  
import java.util.*;
import java.util.concurrent.LinkedBlockingQueue;
public class Main {

public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
Queue<Integer>queue=new LinkedBlockingQueue<Integer>();
for(int o=1;o<=n;o++)
{
int k=sc.nextInt();
int sum=0;
queue.clear();
for(int i=1;i<=k;i++)
{
int cur=sc.nextInt();
queue.add(cur);
sum=sum+cur;
}
int count=0;
while(!queue.isEmpty())
{
int cur1=queue.poll();
count++;
if(queue.isEmpty())
{
break;
}
if(cur1>1)
queue.add(cur1-1);
int cur2=queue.poll();
count++;
if(cur2>1)
queue.add(cur2-1);
}
System.out.print("Case #"+o+": ");
System.out.println(Math.min(sum/2, count));
}
}
}