HDU 5835 Danganronpa
来源:互联网 发布:软件的代理 编辑:程序博客网 时间:2024/04/29 19:33
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 ofn 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?
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 integern . The next line contains n (1≤n≤10) numbers: a1,a2,...,an ,(1≤ai≤100000) .
Each case contains one integer
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中国大学生程序设计竞赛 - 网络选拔赛
样例说明
1个测试样例
有两种礼物
数量分别为3和2
现要求将礼物分配给一排桌子上,每张桌上有一个普通礼物,一个神秘礼物,相邻桌上的普通礼物不能相同,问最多能分配给多少个学生。
考虑到相邻的桌子上礼物不能相同,所以将数量最多的礼物ma隔张桌子放一个,其他的礼物插入其中,故最多可配的学生数为(sum-ma)*2+1。
因为每张桌子上有两种礼物,所以最多可分配给sum/2个学生。综合两种情况考虑即可
代码
#include <iostream>#include <cstdio>#include <algorithm>using namespace std;#define N 20int 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;}
0 0
- HDU 5835 Danganronpa
- hdu 5835 Danganronpa
- HDU 5835 Danganronpa
- HDU 5835 Danganronpa
- hdu 5835 Danganronpa
- hdu 5835 Danganronpa
- HDU 5835 Danganronpa
- HDU 5835 Danganronpa【贪心】
- HDU 5835 Danganronpa
- HDU 5835 Danganronpa 贪心
- HDU 5835-Danganronpa
- HDU 5835 Danganronpa
- HDU 5835Danganronpa
- HDU 5835 Danganronpa
- HDU 5835 Danganronpa(贪心)
- HDU 5835:Danganronpa (不明)
- HDU 5835 Danganronpa (贪心)
- HDU 5835 Danganronpa(贪心)
- Android设置虚线、圆角、渐变
- 数据结构实验之图论四:迷宫探索
- 算法题:马路上的路灯<考察重复数据剔除>
- java 学习第三节--this的用法
- Java并发框架Executor学习(1)——简介
- HDU 5835 Danganronpa
- Git 里面的 origin
- 蓝桥杯 幸运数(java题解)
- hdu5833 Zhu and 772002
- busybox怎么安装
- 如何修改linux主机名
- JAVA中堆和栈的区别
- 关于华为手机使用高德地图无法定位的问题
- POJ 3233 Matrix Power Series