codeforces Codeforces Round #318 div2 A. Bear and Elections 【优先队列】
1 second
256 megabytes
standard input
standard output
Limak is a grizzly bear who desires power and adoration. He wants to win in upcoming elections and rule over the Bearland.
There are n candidates, including Limak. We know how many citizens are going to vote for each candidate. Now i-th candidate would get ai votes. Limak is candidate number 1. To win in elections, he must get strictly more votes than any other candidate.
Victory is more important than everything else so Limak decided to cheat. He will steal votes from his opponents by bribing some citizens. To bribe a citizen, Limak must give him or her one candy - citizens are bears and bears like candies. Limak doesn't have many candies and wonders - how many citizens does he have to bribe?
The first line contains single integer n (2 ≤ n ≤ 100) - number of candidates.
The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 1000) - number of votes for each candidate. Limak is candidate number 1.
Note that after bribing number of votes for some candidate might be zero or might be greater than 1000.
Print the minimum number of citizens Limak must bribe to have strictly more votes than any other candidate.
5
5 1 11 2 8
4
4
1 8 8 8
6
2
7 6
0 题目描述:给你n个人,第二行有n个数,每个数代表第i个人的选票数量。现在第1号人想要赢得选举。所以在选票数量上1号候选人的选票数量
必须严格大于其他候选人的选票数。如果1号候选人的选票不能让他被选举上,他就会去投其他人的。直到他的票数最多。问:他最少需要偷多少张?
(偷的选票可以来自其他的任何人) 将2--n号人的选票数加入到一个大数优先的优先队列。只要1号候选人的票数少于对首人的,就将队首元素取出队列&&值-1, 1号人的+1.计数器+1,再将这个
元素加入到优先队列中。直到1号人的票数>队首元素。 code:
#include <stdio.h>
#include <string.h>
#include <queue>
#include <algorithm> using namespace std; int main()
{
int n;
while(scanf("%d", &n)!=EOF)
{
int head;
priority_queue<int, vector<int>, less<int> >q;
scanf("%d", &head);
int cur;
for(int i=2; i<=n; i++){
scanf("%d", &cur); q.push(cur);
}
int ans=0;
while(head<=q.top())
{
cur=q.top(); q.pop();
head++; cur--; ans++;
q.push(cur);
}
printf("%d\n", ans);
}
return 0;
}
codeforces Codeforces Round #318 div2 A. Bear and Elections 【优先队列】的更多相关文章
- Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2) A. Bear and Elections 优先队列
A. Bear and Elections ...
- Codeforces Beta Round #94 div2 D 优先队列
B. String time limit per test 2 seconds memory limit per test 256 megabytes input standard input out ...
- Codeforces Beta Round #107(Div2)
B.Phone Numbers 思路:就是简单的结构体排序,只是这里有一个技巧,就是结构体存储的时候,直接存各种类型的电话的数量是多少就行,在读入电话的时候,既然号码是一定的,那么就直接按照格式%c读 ...
- Codeforces Beta Round #73(Div2)
A - Chord 题意:就是环中有12个字符,给你三个字符,判断他们之间的间隔,如果第一个和第二个间隔是3并且第二个和第三个间隔是4,那么就输出minor,如果第一个和第二个间隔是4并且第二个和第三 ...
- Codeforces Beta Round #3 D. Least Cost Bracket Sequence 优先队列
D. Least Cost Bracket Sequence 题目连接: http://www.codeforces.com/contest/3/problem/D Description This ...
- Codeforces Round #539 div2
Codeforces Round #539 div2 abstract I 离散化三连 sort(pos.begin(), pos.end()); pos.erase(unique(pos.begin ...
- 【前行】◇第3站◇ Codeforces Round #512 Div2
[第3站]Codeforces Round #512 Div2 第三题莫名卡半天……一堆细节没处理,改一个发现还有一个……然后就炸了,罚了一啪啦时间 Rating又掉了……但是没什么,比上一次好多了: ...
- Codeforces Round#320 Div2 解题报告
Codeforces Round#320 Div2 先做个标题党,骗骗访问量,结束后再来写咯. codeforces 579A Raising Bacteria codeforces 579B Fin ...
- Codeforces Round #564(div2)
Codeforces Round #564(div2) 本来以为是送分场,结果成了送命场. 菜是原罪 A SB题,上来读不懂题就交WA了一发,代码就不粘了 B 简单构造 很明显,\(n*n\)的矩阵可 ...
随机推荐
- 继续聊WPF——动态数据模板
我为啥称之为“动态数据模板”?先看看下面的截图,今天,我们就是要实现这种功能. 大概是这样的,我们定义的DataTemplate是通过触发器动态应用到 ComboBoxItem 上. 这个下拉列表控件 ...
- knockout Ajax异步无刷新分页 Demo +mvc+bootstrap
最近工作中web客户端需要用到knockout,在此记录下一些Demo,以后用到的时候查找起来方便.也希望给新入门的knockout使用者一点经验.knockout官方文档.这儿是一个使用knocko ...
- Laravel5.1 数据库--DB运行原生SQL
Laravel操作数据库有三种:DB原生SQL.构建器.Model.这三种依情况而决定使用哪种更合适. 那么今儿咱就从DB原生SQL说起: 1 用DB门面原生SQL语句操作 用DB门面操作的话呢 无非 ...
- 制作dos启动u盘
需要准备的工具: 空U盘的U盘HP优盘启动盘格式化工具 链接:https://pan.baidu.com/s/1i59wgUp 密码:l5ke 1.1插入U盘,打开 HP优盘启动盘格式化工具 1. ...
- python MD5操作
def my_md5(str): import hashlib new_str = str.encode() #把字符串转成bytes类型 # new_str = b'%s'%str #把字符串转成b ...
- vs报错找不到错在哪里!Validation failed for one or more entities
今天在处理Entity Framework修改数据库时,报错: Validation failed for one or more entities. See 'EntityValidationErr ...
- On the fly test
on the fly test就是边开发边测试的意思.test code不是早就生成好的,在一边生成code的同时一边做test running,最大的好处是,flexiable ,每一次可以选择不同 ...
- 调用第三方物流公司API即时查询物流信息
主要是利用快递鸟提供的物流服务,通过对接快递鸟的API,调用即时查询接口,获取物流信息. 这里采用java语言,调用快递鸟的接口为例.步骤如下: 1.首先,得去快递鸟的官方网站注册一个账号并进行实名认 ...
- AGS Server 10.1 切图工具
在AGS Sever中很重要的功能就是地图缓存的制作,安装AGS Sever会在catalog中增加相关的工具箱,利用这些工具可以制作.删除.更新切片 一.Convert map server cac ...
- SQL SERVER临时表的使用
SQL SERVER临时表的使用 drop table #Tmp --删除临时表#Tmpcreate table #Tmp --创建临时表#Tmp( ID int IDENTITY (1 ...