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

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5835

****************************************************

题意:有T组测试实例,每组实例有n种类型的礼物,第i种类型的礼物共有a[i]个,相邻同学的礼物不能相同,问有多少个同学能拿到符合要求的礼物。

分析:从这道题里我学到了勇于尝试的重要性%>_<%~ 脑洞尽管开,试一试不会亏呀

这道题里并没有要求童鞋们要挨着坐,所以嘞,随便坐喽,这说明了神马,这就说明了这是一道水题%>_<%~

只需要判断一人俩礼物能分几个人的问题。。。。

那些还在研究怎么坐得到的结果最多又怎么实现的童鞋们~~~你们都被出题的人给坑坏了

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <algorithm>
 5 #include <cmath>
 6 #include <stack>
 7 #include <map>
 8 #include <vector>
 9 using namespace std;
10 
11 #define N 12000
12 #define INF 0x3f3f3f3f
13 
14 int a[N];
15 
16 int main()
17 {
18     int T,n,i,sum,k=1;
19 
20     scanf("%d", &T);
21 
22     while(T--)
23     {
24         sum=0;
25         scanf("%d", &n);
26 
27         for(i=0;i<n;i++)
28         {
29             scanf("%d", &a[i]);
30             sum+=a[i];
31         }
32 
33         printf("Case #%d: ",k++);
34         if(sum==1)
35             printf("1\n");
36         else
37             printf("%d\n", sum/2);
38     }
39     return 0;
40 }

 

附上一个让不明白的人更明白的代码:

 1 #include <iostream>
 2 #include <stdio.h>
 3 #include <string.h>
 4 #include <string>
 5 #include <vector>
 6 #include <algorithm>
 7 #include <map>
 8 #include <queue>
 9 #include <stack>
10 #include <math.h>
11 
12 using namespace std;
13 
14 #define met(a, b) memset(a, b, sizeof(a))
15 #define N 53
16 #define INF 0x3f3f3f3f
17 #define PI 4*atan(1)
18 const int MOD = 10000007;
19 
20 typedef long long LL;
21 
22 int a[N];
23 
24 int main()
25 {
26     int T, t = 1, n, sum;
27     scanf("%d", &T);
28     while(T--)
29     {
30         sum = 0;
31         scanf("%d", &n);
32 
33         for(int i=1; i<=n; i++)
34         {
35             scanf("%d", &a[i]);
36             sum += a[i];
37         }
38 
39         sort(a+1, a+n+1);
40         
41         int half = sum/2;
42         
43         int s = sum-a[n];
44    
45         if(2*s+1 < half)
46             printf("Case #%d: %d\n", t++, 2*s+1);
47         else
48             printf("Case #%d: %d\n", t++, half);
49     }
50     return 0;
51 }

 

posted on 2016-08-14 18:52  惟愿。。。  阅读(337)  评论(0编辑  收藏  举报