HDU 5835 Danganronpa 贪心
Danganronpa
题目连接:
http://acm.hdu.edu.cn/showproblem.php?pid=5835
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:
Each table will be prepared for a mysterious gift and an ordinary gift.
In order to reflect the Chisa Yukizome's generosity, the kinds of the ordinary gift on the adjacent table must be different.
There are no limits for the mysterious gift.
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
Hint
题意
有n类礼物,每个礼物有a[i]个,然后你要分发给尽量多的小朋友,使得每个小朋友都有一个神秘礼物和普通礼物,要求相邻的小朋友的普通礼物都不相同。
题解:
首先答案肯定是小于等于sum/2,因为每个小朋友得有2礼物。
然后我们考虑最大的礼物,我们先每个小朋友一个大礼物,然后再分其他礼物。
相邻的交替用大礼物当神秘礼物就好了。
至于sum/2,这个显然是错的啊,比如数据就一种礼物,这个礼物有5个。
代码
#include<bits/stdc++.h>
using namespace std;
const int maxn = 15;
int a[maxn],cas;
int main(){
int t;
scanf("%d",&t);
while(t--){
int n,mx=0,sum=0;
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
mx=max(a[i],mx);
sum+=a[i];
}
int ans=min(sum/2,(sum-mx)*2+1);
printf("Case #%d: %d\n",++cas,ans);
}
}
HDU 5835 Danganronpa 贪心的更多相关文章
- HDU 5835 Danganronpa(弹丸论破)
Danganronpa(弹丸论破) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Other ...
- 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 4864(Task 贪心)(Java实现)
Hdu 4864(Task 贪心) 原题链接 题意:给定n台机器和m个任务,任务和机器都有工作时间值和工作等级值,一个机器只能执行一个任务,且执行任务的条件位机器的两个值都大于等于任务的值,每完成一个 ...
- D - 淡黄的长裙 HDU - 4221(贪心)
D - 淡黄的长裙 HDU - 4221(贪心) James is almost mad! Currently, he was assigned a lot of works to do, so ma ...
- 【HDU 5835】Danganronpa(分配礼物)
10种礼物,每种有ai个,每个小朋友分两个礼物,其中普通礼物要求相邻两人的不能一样,求最多分给几个小朋友. sum/2是最多的情况.什么时候发不了那么多,就是当max很大,无论怎么发,都发不完max. ...
随机推荐
- FFmpeg编码扩展之————编码库的扩展(libfdk-aac)
ffmpeg windows版没有libfdk-acc 请求该地址下载:http://tmod.nmm-hd.org/FFmpeg/
- AngulaJs -- 隔离作用域
具有隔离作用域的指令最主要的使用场景是创建可复用的组件 创建具有隔离作用域的指令需要将scope属性设置为一个空对象{}.如果这样做了,指令的 模板就无法访问外部作用域了: <div ng-co ...
- 【ARTS】01_05_左耳听风-20181210~1216
ARTS: Algrothm: leetcode算法题目 Review: 阅读并且点评一篇英文技术文章 Tip/Techni: 学习一个技术技巧 Share: 分享一篇有观点和思考的技术文章 Algo ...
- House Robber I & II & III
House Robber You are a professional robber planning to rob houses along a street. Each house has a c ...
- 终极利器!利用appium和mitmproxy登录获取cookies
环境搭建 参考我之前写的https://www.cnblogs.com/c-x-a/p/9163221.html appium 代码start_appium.py # -*- coding: utf- ...
- python进阶之魔法函数
__repr__ Python中这个__repr__函数,对应repr(object)这个函数,返回一个可以用来表示对象的可打印字符串.如果我们直接打印一个类,向下面这样 class A(): ...
- elasticsearch常用配置
允许外网连接network.host,http.port,network.publish_host,network.bind_host别的机器或者网卡才能访问,否则只能是127.0.0.1或者loca ...
- JVM(3)对象A和B循环引用,最后会不会不被GC回收?-------关于Java的GC机制
①首先说一下,GC里边在JVM其中是使用的ROOT算法,ROOT算法,什么称作为ROOT呢,就是说类的静态成员,静态成员就是static修饰的那种,是"根"的一个,根还包含方法中的 ...
- Java 抽象类和抽象方法
包含抽象方法的类叫抽象类,如果一个类中包含一个或多个抽象方法,该类必须被限定为抽象的,否则编译器会报错,抽象类不可创建对象,创建抽象类的对象编译器会报错 如果从一个抽象类继承,并想创建该新类的对象,那 ...
- vs2010下sort比较函数链接错误问题
环境:win7 + vs2010 + C++ 实现vector的sort算法,在类的头文件中写入比较函数时会出现链接错误: error LNK2005: "bool __cdecl comp ...