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);}
}

转载于:https://www.cnblogs.com/qscqesze/p/5771084.html

HDU 5835 Danganronpa 贪心相关推荐

  1. HDU 5835 Danganronpa(弹丸论破)

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

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

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

  3. HDU 5835 Danganronpa

    ...神特么弹丸论破 有n种礼物,每种礼物a[I]个,现在有一排无限长的桌子,要往上面放礼物,每个桌子放两个礼物,第一个礼物要求相邻的桌子第一个礼物是不同的,第二个礼物没有这个要求,可以随便选一种礼物 ...

  4. hdu 5248(二分+贪心)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5248 解题思路:这道题我原本的思路是动态规划,结果看到数很大,结果放弃了.然后想到二分,思路是对的,只 ...

  5. hdu 5246(贪心)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5246 解题思路:先排序,在采用贪心的方法,先给百小度找到合适的初始战斗力,找到比初始战斗力上限小的中最 ...

  6. hdu 4296 Buildings (贪心)

    http://acm.hdu.edu.cn/showproblem.php?pid=4296 题意: 给出n个石板的重量w和它的承受能力s,将这n个石板累在一起,这样每个石板都有一个PDV = (Σw ...

  7. HDU - 6438(贪心+思维)

    链接:HDU - 6438 题意:给出 n ,表示 n 天.给出 n 个数,a[i] 表示第 i 天,物品的价格是多少.每天可以选择买一个物品,或者卖一个已有物品,也可以什么都不做,问最后最大能赚多少 ...

  8. HDU 4023 (博弈 贪心 模拟) Game

    如果硬要说这算是博弈题目的话,那这个博弈是不公平博弈(partizan games),因为双方面对同一个局面做出来的决策是不一样的. 我们平时做的博弈都是公平博弈(impartial games),所 ...

  9. HDU - 6746 Civilization(贪心+模拟)

    题目链接:点击查看 题目大意:中文题面 题目分析:一道比赛时写崩了的模拟,赛后参考别人的代码,发现原来这个题目可以写的如此简单 说会题目,n 只有 500 ,可以 n * n 枚举每个位置作为起点,对 ...

最新文章

  1. IOS UITableView 加载未知宽高图片的解决方案
  2. 前端每日实战:142# 视频演示如何用 CSS 的 Grid 布局创作一枚小鸡邮票
  3. 连接moogDB数据库
  4. 前端学习(2604):增加响应头可以获取数据
  5. 排队五小时才能吃上一口的Popeyes,要借阿里云数据中台10年内开足1500家门店
  6. 简述oracle数据库特殊状态,【OracleDB】 01 概述和基本操作
  7. apex您所在的地区目前不提供此物品_《APEX英雄》入门指南传奇篇-命脉
  8. 基础面试题——HTML/CSS
  9. XMPP的简介和基本概念
  10. L2-028 秀恩爱分得快-PAT团体程序设计天梯赛GPLT
  11. 用javascript+PHP随机显示图片
  12. Mac OSX用终端检测文件的sha1值
  13. EasyAR初学者教程
  14. 实时频谱分析仪作下变频器的技术实现
  15. SVG黑科技微信排版『层层左右交错滑开』模板代码
  16. php图片上传存储源码,可实现预览
  17. Lazada打造爆款秘籍
  18. 学会做arduino交通灯
  19. 复杂网络中重要节点挖掘方法综述
  20. 【操作系统】-- 先来先服务算法(FCFS)、短作业优先算法(SJF)、高响应比调度算法(HRRN)

热门文章

  1. android+模拟器上gdb,使用gdb在Android Emulator中进行调试c程序
  2. 设计模式UML类图(摘至《HeadFirst设计模式》)
  3. [SPOJGCJ1C09C] Bribe the Prisoners
  4. Mozilla 的 Flash 杀手 'Shumway' 已经现身
  5. STL札记2(序列容器vector、list、deque)
  6. 读《python核心编程2》笔记 1
  7. 出版新书《从毕业生到程序员 使用C#开发商业软件》
  8. (12) 需求征集 -- 序列管理、编号管理
  9. Python开发规范
  10. 云大计算机昆工,云南最好的7所大学,分3档!本地人青看中昆医大,外省更爱昆工!...