HDU 5835 Danganronpa(弹丸论破)
HDU 5835 Danganronpa(弹丸论破)
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
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? |
雪染千纱是某学校的老师。她准备了许多礼物,共n种,每种a[i]件,在班会上发给学生。诸事繁杂,她只好把礼物交给班长千秋七海。由于学校设计神奇,学生的课桌只有一排。千秋七海希望如此安排礼物: 1.每张桌子都将准备一份神秘礼物和一份普通礼物。 2.为了彰显雪染千纱的大方,相邻桌子的普通礼物必须不同。 3.神秘礼物没有限制。 4.礼物必须连续发放。 她想知道最多有多少学生可以因此获得礼物(假设学生数量无限多)。作为她最重要的人,你必定对此问题手到擒来。 |
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). |
输入的第一行是一个整数 T(T≤10)表示测试用例的数量。 每个测试用例都有一个整数n。下一行有 n (1≤n≤10)个数: 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. |
对于每个测试用例,输出一行“Case #x: y”(没有引号),x表示测试用例的编号(从1开始)并且y表示七海千秋问题的答案。 |
Sample Input - 输入样例 |
Sample Output - 输出样例 |
1 |
Case #1: 2 |
【题解】
水题,对礼物a[i]升序排序,求相邻没有相同种类礼物的排列长度(可横可竖),然后用最后若剩余礼物>前面长度,取前面长度,否则为 剩余礼物+(前面长度-剩余礼物)/2
【代码 C++】
- #include <cstdio>
- #include <algorithm>
- int data[];
- int main(){
- int t, n, iT, i, s, opt;
- scanf("%d", &t);
- for (iT = ; iT <= t; ++iT){
- printf("Case #%d: ", iT);
- scanf("%d", &n);
- for (i = ; i < n; ++i) scanf("%d", &data[i]);
- std::sort(data, data + n);
- for (i = s = ; i < n - ; ++i){
- s += data[i] << ; data[i + ] -= data[i];
- }
- if (data[i] < s) opt = data[i] + (s - data[i]) / ;
- else opt = s;
- printf("%d\n", opt);
- }
- return ;
- }
HDU 5835 Danganronpa(弹丸论破)的更多相关文章
- HDU 5835 Danganronpa (贪心)
Danganronpa 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5835 Description Chisa Yukizome works as ...
- HDU 5835 Danganronpa 贪心
Danganronpa 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5835 Description Chisa Yukizome works as ...
- HDU 5835 Danganronpa
Danganronpa Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total ...
- HDU 5835 Danganronpa (水题)
题意:给定 n 个礼物有数量,一种是特殊的,一种是不特殊的,要分给一些人,每人一个特殊的一个不特殊,但是不特殊的不能相邻的,问最多能分给多少人. 析:是一个比较简单的题目,我们只要求差值就好,先算第一 ...
- [ An Ac a Day ^_^ ] hdu 5835 Danganronpa 令人发指
这道题告诉我两个道理: 1.记得写case 要不挂死你 2.数据很水的时候 只有样例的这一种情况…… 原来数据可以这么水…… #include<stdio.h> #include<i ...
- Hdu 5384 Danganronpa (AC自动机模板)
题目链接: Hdu 5384 Danganronpa 题目描述: 给出n个目标串Ai,m个模式串Bj,问每个目标串中m个模式串出现的次数总和为多少? 解题思路: 与Hdu 2222 Keywords ...
- 【HDU 5835】Danganronpa(分配礼物)
10种礼物,每种有ai个,每个小朋友分两个礼物,其中普通礼物要求相邻两人的不能一样,求最多分给几个小朋友. sum/2是最多的情况.什么时候发不了那么多,就是当max很大,无论怎么发,都发不完max. ...
- hdu 5384 Danganronpa
链接:http://acm.hdu.edu.cn/showproblem.php?pid=5384 思路:没学自动机时以为是道KMP然后就tle了好几把,AC自动机模板题 #include<cs ...
- HDU 5384——Danganronpa——————【AC自动机】
Danganronpa Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Tot ...
随机推荐
- redis 笔记06 发布与订阅、事务、慢查询日志、监视器
发布与订阅 1. 服务器状态在pubsub_channels字典保存了所有频道的订阅关系:SUBSCRIBE命令负责将客户端和被订阅的频道关联到这个字典里面,而UNSUBSCRIBE命令则负责 解除客 ...
- Mongodb 笔记05 创建副本集
创建副本集 1. 副本集:副本集时一组服务器,其中有一个主服务器(primary),用于处理客户端请求:还有多个备份服务器(secondary),用于保存主服务器的数据副本.如果主服务器崩溃了,备份服 ...
- IEnumerator:概念详解
IEnumerable接口是非常的简单,只包含一个抽象的方法GetEnumerator(),它返回一个可用于循环访问集合的IEnumerator对象.IEnumerator对象有什么呢?它是一个真正的 ...
- ubuntu下配置java环境【转】
转自:http://www.cnblogs.com/fnng/archive/2013/01/30/2883815.html 配置JDK环境 下载 登录oracle的网站去下载JDK7 http:// ...
- linux进程的堆栈空间_代码段(指令,只读)、数据段(静态变量,全局变量)、堆栈段(局部变量)、栈【转】
转自:http://blog.csdn.net/gongweijiao/article/details/8207333 原文参见:http://blog.163.com/xychenbaihu@yea ...
- oracle 数据泵 详解
导出数据 1)按用户导 expdp scott/tiger@orcl schemas=scott dumpfile=expdp.dmp DIRECTORY=dir logfile=expdp.log ...
- 怎么使用Docker搭建PHP开发环境呢?
在Docker流行之前,要搭建开发环境通常有两种选择:一种是使用wamp.xampp.mamp等集成开发环境安装包,另外一种就是使用普通虚拟机来安装linux服务器,然后通过下载一键安装包(如:lnm ...
- PHP实现单例模式
<?php /** * [单例模式] * 总结:防止外部new对象:防止子类继承:防止克隆. */ header("Content-type: text/html; charset=u ...
- svn down代码的时候提示“由于目标计算机积极拒绝,无法连接”
如上图所示: 原因1:svn没有启动成功 原因2:防火墙没有svn的端口号3690 解决方法: 1.启动svn服务 svnserve -d -r svn路径 例如:svnserve -d -r / ...
- HTML5与CSS3权威指南
第一章:Web时代的变迁 HTML5放心使用的理由: 兼容性:HTML5在老板本的浏览器上也可以正常运行: 实用性:HTML5内部并没有封装什么很复杂的,不切实际的功能,而只是封装了简单实用的功能: ...