您的位置:首页 > 其它

HDU 5835 Danganronpa【贪心】

2016-08-16 17:02 330 查看


Danganronpa

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 550    Accepted Submission(s): 398


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

 

Author

UESTC

 

Source

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

 

①找规律
首先每种情况的最大答案就是SUM/2。
下面就判断能不能达到SUM/2,如果某种礼物的数量远远超过了其余种类的数量和那么就不能达到,
这里,我先将所有礼物sort了一下,从小到大排序,把前n-1种礼物数量加起来,记为sum1,如果
sum1>=sum/2/2,那么就可以达到最大答案sum/2,否则答案是:sum1*2+1。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<climits>
#include<string>
#include<queue>
#include<stack>
#include<algorithm>
using namespace std;
#define rep(i,j,k)for(i=j;i<k;i++)
#define per(i,j,k)for(i=j;i>k;i--)
#define MS(x,y)memset(x,y,sizeof(x))
typedef long long LL;
const int INF =0x7FFFFFFF;

const int M=1e5+1;
int num[M];
int i,j,k,n,t,sum,sum1;

int main()
{
scanf("%d",&t);
rep(k,1,t+1)
{
sum=0;sum1=0;
scanf("%d",&n);
rep(i,0,n){
scanf("%d",&num[i]);
sum+=num[i];
}
sort(num,num+n);
rep(i,0,n-1){
sum1+=num[i];
}
if(sum1>=sum/2/2)
printf("Case #%d: %d\n",k,sum/2);
else printf("Case #%d: %d\n",k,sum1*2+1);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: