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:

  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

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 贪心的更多相关文章

  1. HDU 5835 Danganronpa(弹丸论破)

     Danganronpa(弹丸论破) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Other ...

  2. HDU 5835 Danganronpa (贪心)

    Danganronpa 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5835 Description Chisa Yukizome works as ...

  3. HDU 5835 Danganronpa

    Danganronpa Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total ...

  4. HDU 5835 Danganronpa (水题)

    题意:给定 n 个礼物有数量,一种是特殊的,一种是不特殊的,要分给一些人,每人一个特殊的一个不特殊,但是不特殊的不能相邻的,问最多能分给多少人. 析:是一个比较简单的题目,我们只要求差值就好,先算第一 ...

  5. [ An Ac a Day ^_^ ] hdu 5835 Danganronpa 令人发指

    这道题告诉我两个道理: 1.记得写case 要不挂死你 2.数据很水的时候 只有样例的这一种情况…… 原来数据可以这么水…… #include<stdio.h> #include<i ...

  6. Hdu 5384 Danganronpa (AC自动机模板)

    题目链接: Hdu 5384 Danganronpa 题目描述: 给出n个目标串Ai,m个模式串Bj,问每个目标串中m个模式串出现的次数总和为多少? 解题思路: 与Hdu 2222  Keywords ...

  7. Hdu 4864(Task 贪心)(Java实现)

    Hdu 4864(Task 贪心) 原题链接 题意:给定n台机器和m个任务,任务和机器都有工作时间值和工作等级值,一个机器只能执行一个任务,且执行任务的条件位机器的两个值都大于等于任务的值,每完成一个 ...

  8. D - 淡黄的长裙 HDU - 4221(贪心)

    D - 淡黄的长裙 HDU - 4221(贪心) James is almost mad! Currently, he was assigned a lot of works to do, so ma ...

  9. 【HDU 5835】Danganronpa(分配礼物)

    10种礼物,每种有ai个,每个小朋友分两个礼物,其中普通礼物要求相邻两人的不能一样,求最多分给几个小朋友. sum/2是最多的情况.什么时候发不了那么多,就是当max很大,无论怎么发,都发不完max. ...

随机推荐

  1. jenkins设置CSRF 协议(CRUMB值设置)

    在关闭“”调用出现Error 403 No valid crumb was included in the request 第一种解决方式是 关闭 csrf,如上图,去掉勾就可以,但是并不推荐. 第二 ...

  2. 给定一个整数,求解该整数最少能用多少个Fib数字相加得到

    一,问题描述 给定一个整数N,求解该整数最少能用多少个Fib数字相加得到 Fib数列,就是如: 1,1,2,3,5,8,13.... Fib数列,满足条件:Fib(n)=Fib(n-1)+Fib(n- ...

  3. CSS规范 - 最佳实践--(来自网易)

    最佳选择器写法(模块) /* 这是某个模块 */ .m-nav{}/* 模块容器 */ .m-nav li,.m-nav a{}/* 先共性 优化组合 */ .m-nav li{}/* 后个性 语义化 ...

  4. C标准库函数中复杂的函数声明

    <signal.h> 中有一个复杂的函数声明.很叫人费解. void (*signal(int sig, void (*handler)(int)))(int); 我们按照向右看向左看的黄 ...

  5. 20155314 2016-2017-2 《Java程序设计》第6周学习总结

    20155314 2016-2017-2 <Java程序设计>第6周学习总结 教材学习内容总结 理解流与IO 理解InputStream/OutPutStream的继承架构 理解Reade ...

  6. Anaconda+django写出第一个web app(六)

    今天学习如何写一个注册用户的界面. 上一节的导航栏中我们修改了导航栏右侧的文字为register并将路径设置为/register,内容如下: <li><a href="/r ...

  7. insert into与insert ignore以及replace into的区别

    insert ignore表示,如果表中已经存在相同的记录,则忽略当前新数据: INSERT INTO有无数据都插入,如果主键则不插入; REPLACE INTO 如果是主键插入则会替换以前的数据; ...

  8. nginx_upstream_check_module监控后端服务器http

    nginx_upstream_check_module 是专门提供负载均衡器内节点的健康检查的外部模块,由淘宝的姚伟斌大神开发,通过它可以用来检测后端 realserver 的健康状态.如果后端 re ...

  9. 【Unity_UWP】Unity 工程发布win10 UWP 时的本地文件读取 (上篇)

    Universal Windows Platform(UWP)是微软Windows10专用的通用应用平台,其目的在于在统一操作系统下控制所有智能电子设备. 自从Unity 5.2之后,配合VS 201 ...

  10. Windows下安装Python requests模块

    在使用自己写的或者别人的python小工具时可能会出现类似ImportError: No module named Requests的问题: D:\tool\python\fuzz>Fuzz.p ...