HDU 5835 Danganronpa

5 篇文章 0 订阅
3 篇文章 0 订阅

Danganronpa

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


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
 

Author
UESTC
 

Source

样例说明

1个测试样例
有两种礼物
数量分别为3和2
现要求将礼物分配给一排桌子上,每张桌上有一个普通礼物,一个神秘礼物,相邻桌上的普通礼物不能相同,问最多能分配给多少个学生。

考虑到相邻的桌子上礼物不能相同,所以将数量最多的礼物ma隔张桌子放一个,其他的礼物插入其中,故最多可配的学生数为(sum-ma)*2+1。
因为每张桌子上有两种礼物,所以最多可分配给sum/2个学生。综合两种情况考虑即可

代码

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
#define N 20
int T,n,ans,sum,ma;
int a[N];
int main()
{
	scanf("%d",&T);
	for(int t=1;t<=T;t++)
	{
		sum=0;
		ma=0;
		cin>>n;
		for(int i=1;i<=n;i++)
		{
		  cin>>a[i];
		  sum+=a[i];
		  ma=max(ma,a[i]);
		}
		ans=min(sum/2,(sum-ma)*2+1);
		printf("Case #%d: %d\n",t,ans);
	}
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值