hdu-5835-续缘之路
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 | 1 |
Sample Output
1 | Case #1: 2 |
题解
具体做法:维护一个队列 首先可以知道答案不超过所有礼物之和的二分之一(重要!!!),那么通过一个队列来模拟发礼物的过程,将每个礼物的个数放入队列,然后弹出一个判断两个条件:1.如果大于1就减去1然后放入队列尾部,然后将结果加一。2.队列里是否还有下一个元素,也就是要满足题目中不同礼物相隔这个条件。 最后判断如果结果大于所有礼物之和的二分之一,那说明每一个人都能按题意拿到普通礼物,剩下的就都是神秘礼物就可以了。## AC code:(不包含输入类)
1 | import java.io.*; |