Codeforces Round #318 (Div. 2) A - Bear and Elections 模拟暴力枚举

8 篇文章 0 订阅
8 篇文章 0 订阅

题意:有n个人参加选举,每个人的得票分别为 ai ,一个人赢的意思是这个人的票大于其他所有人的票。现在1想要赢得选举,他有一个操作就是将其他人的选票贿赂过来,现在问最少需要贿赂多少个人。

因为数据比较小。直接模拟

//author: CHC
//First Edit Time:  2015-09-01 10:49
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <algorithm>
#include <limits>
using namespace std;
typedef long long LL;
const int MAXN=1e+4;
const int INF = numeric_limits<int>::max();
const LL LL_INF= numeric_limits<LL>::max();
int A[MAXN],n;
bool check(){
    for(int i=2;i<=n;i++){
        if(A[i]>=A[1])return false;
    }
    return true;
}
int main()
{
    while(~scanf("%d",&n)){
        for(int i=1;i<=n;i++){
            scanf("%d",&A[i]);
        }
        int cnt=0;
        while(1){
            if(check())break;
            int maxn=2;
            for(int i=2;i<=n;i++)
                if(A[i]>A[maxn])maxn=i;
            ++cnt;
            A[1]++;
            A[maxn]--;
        }
        printf("%d\n",cnt);
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值