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?
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中国大学生程序设计竞赛 - 网络选拔赛
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
- HDU5835-Danganronpa
- HDU5835 Danganronpa(简单推理)
- 2016中国大学生程序设计竞赛 - 网络选拔赛 1004 Danganronpa hdu5835
- Danganronpa
- Danganronpa
- Danganronpa
- Danganronpa
- Danganronpa
- HDU5384 Danganronpa
- hdu5384 Danganronpa
- HDU Danganronpa
- Danganronpa HDU
- 【HDOJ 5384】Danganronpa
- hdu 5384 Danganronpa
- HDU 5384 Danganronpa
- hdu-Danganronpa(AC自动机)
- hdu5384 Danganronpa(AC自动机)
- HDOJ 5384 Danganronpa
- PNG文件结构分析 ---Png解析
- SylixOS中AHCI驱动框架分析
- C++中的类,类中定义该类的指针的用途
- DHTML技术综合演示---示例:表格行间隔显示
- [LeetCode]263. Ugly Number
- HDU5835-Danganronpa
- Java多线程系列--“JUC集合”08之 LinkedBlockingQueue
- AsyncTask(异步)和Thread(线程)的使用与对比
- Oracle笔记(九) 表的创建及管理
- 一些Java面试题
- 深度学习
- /***/二叉树经典面试题之判断一棵二叉树是否是完全二叉树
- Java多线程系列--“JUC集合”09之 LinkedBlockingDeque
- Kaggle入门