HDU5835-Danganronpa

来源:互联网 发布:南天软件待遇 编辑:程序博客网 时间:2024/06/05 12:46

Danganronpa

                                                                             Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
                                                                                                          Total Submission(s): 766    Accepted Submission(s): 544


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
123 2
 

Sample Output
Case #1: 2
 

Author
UESTC
 

Source
2016中国大学生程序设计竞赛 - 网络选拔赛
 

Recommend
wange2014
 

题意:有n种礼物,每种礼物有a[i]个,给一排的学生发礼物,每个人至少一个普通礼物和一个神秘礼物,相邻的学生不能有相同的普通礼物,问最多有几个学生能得到礼物

解题思路:模拟,先将礼物数量从小到大排序,礼物总数为sum,最多能有sum/2个学生能得到礼物,然后最少的礼物和最多的礼物交替当作普通礼物发给学生


#include <iostream>  #include <cstdio>  #include <cstring>  #include <string>  #include <algorithm>  #include <cmath>  #include <map>  #include <cmath>  #include <set>  #include <stack>  #include <queue>  #include <vector>  #include <bitset>  #include <functional>  using namespace std;#define LL long long  const int INF = 0x3f3f3f3f;int a[100];int sum;int main(){int t,n,cas=0;scanf("%d", &t);while (t--){scanf("%d", &n);sum = 0;for (int i = 0; i < n; i++){scanf("%d", &a[i]);sum += a[i];}sort(a, a + n);int ans = 0;sum = sum / 2;int l = 0, r = n - 1;while (l <= r){a[r]--,ans++;if(l!=r) a[l]--, ans++;else break;if (!a[l]) l++;if (!a[r]) r--;if (ans > sum) {ans = sum; break;}}if (ans > sum) ans = sum;printf("Case #%d: %d\n",++cas, ans);}return 0;}

0 0
原创粉丝点击