【2016 CCPC 网络赛 】D Danganronpa

Danganronpa

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


 

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

扫描二维码关注公众号,回复: 2865377 查看本文章

Author

UESTC

Source

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

问题链接:HDU5835 Danganronpa

问题大意:给你n种礼物每种礼物有ai个(1≤ai≤100000),现在有排成一行的学生,你要给每个学生分发两个礼物:一个一般礼物,一个神秘礼物。分发要求:1.分发礼物的学生要连续 2.相邻学生的一般礼物不能相同 3.对神秘礼物的分发没有要求。问对于给定礼物种类数和各种礼物个数最多能给多少学生分发

题解:设礼物的总个数为sum,那么答案不会超过sum/2(一个人2个礼物),由于分发特殊礼物没有要求,因此只考虑一般礼物就行,只要记录上次取的礼物种类就行,此次取的种类要和上次取的不同,具体看代码

AC的C++程序:

#include<iostream>

using namespace std;

int main()
{
	int t,n,a[15];//a数组存储种类i的礼物个数 
	scanf("%d",&t);
	for(int i=1;i<=t;i++)
	{
		int sum=0;
		scanf("%d",&n);
		for(int j=0;j<n;j++)
		{
			scanf("%d",&a[j]);
			sum+=a[j];
		}
		sum/=2;
		int pre=-1,ans=0;//pre标记上次取的礼物的种类,ans记录答案  
		for(;;)
		{
			int k=0;
			while(k<n&&(a[k]==0||a[k]==pre))//当礼物 k没有了或者是上次取的礼物就不能取这个礼物 
			  k++;
			if(k==n)//如果找不到就退出 
			  break; 
			else
			{
				a[k]--;//这种礼物数量减一 
				pre=k;//更新pre 
				ans++;//人数加一 
				if(ans==sum)//如果人数达到了上限就退出 
				  break;
			}
		}
		printf("Case #%d: %d\n",i,ans);
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/SongBai1997/article/details/81737182
今日推荐