zoukankan      html  css  js  c++  java
  • CF div2 318 A

    A. Bear and Elections

    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?

    Input

    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.

    Output

    Print the minimum number of citizens Limak must bribe to have strictly more votes than any other candidate.

    Sample test(s)
    Input
    5
    5 1 11 2 8
    Output
    4
    Input
    4
    1 8 8 8
    Output
    6
    Input
    2
    7 6
    Output
    0
    Note

    In the first sample Limak has 5 votes. One of the ways to achieve victory is to bribe 4 citizens who want to vote for the third candidate. Then numbers of votes would be 9, 1, 7, 2, 8 (Limak would have 9 votes). Alternatively, Limak could steal only 3 votes from the third candidate and 1 vote from the second candidate to get situation 9, 0, 8, 2, 8.

    In the second sample Limak will steal 2 votes from each candidate. Situation will be 7, 6, 6, 6.

    In the third sample Limak is a winner without bribing any citizen.

    A题 题意大致是有N个人选举每个人有ai票,第一个人可以从其他候选人那偷票,问最少要偷几张票才能让第一个人获胜

    开始写的时候想到直接模拟每次排序取最大的和第一个比较这样写的好SB 后来想可以直接用优先队列搞

     1 #include <cstdio>
     2 #include <cstring>
     3 #include <iostream>
     4 #include <queue>
     5 #include <vector>
     6 #include <stack>
     7 #include <algorithm>
     8 
     9 using namespace std;
    10 
    11 const int M = 10005;
    12 const int maxn = 5000;
    13 typedef long long ll;
    14 
    15 vector<int>G[maxn];
    16 queue<int>Q;
    17 stack<int>st;
    18 
    19 priority_queue<int>q;
    20 
    21 int a[maxn];
    22 
    23 int main()
    24 {
    25 
    26     int n;
    27     int ans = 0;
    28     int id=0;
    29     scanf("%d",&n);
    30     int tmp = -1;
    31     for(int i=0;i<n;i++){
    32         scanf("%d",&a[i]);
    33         if(i!=0)
    34             q.push(a[i]);
    35 
    36     }
    37 
    38     if(q.top() < a[0]) printf("0
    ");
    39     else {
    40             int t;
    41             int res = ans = a[0];
    42         while(res <= q.top()){
    43              t = q.top();
    44              q.pop();
    45             t--;
    46             res++;
    47             q.push(t);
    48         }
    49 
    50     printf("%d
    ",res-ans);
    51     }
    52 
    53 
    54 
    55     return 0;
    56 }
    View Code
    It is loneliness that make you different,not gregariousness
  • 相关阅读:
    15年里,对您触动最大的中西方管理著作或思想是什么?
    [代言]加入微软中国研发团队的机会
    CSS3 column属性族firefox浏览器下的问题
    JavaScript中__proto__与prototype的关系
    JavaScript对象模型执行模型
    【转】一步一步学Linq to sql(九):其它补充
    WPF基础之样式设置和模板化
    【转】一步一步学Linq to sql(十):分层构架的例子
    WPF基础之基元素
    WPF基础之属性系统
  • 原文地址:https://www.cnblogs.com/lmlyzxiao/p/4811491.html
Copyright © 2011-2022 走看看