题意:有n个人参加选举,每个人的得票分别为ai,一个人赢的意思是这个人的票大于其他所有人的票。现在1想要赢得选举,他有一个操作就是将其他人的选票贿赂过来,现在问最少需要贿赂多少个人。
因为数据比较小。直接模拟
#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; }
|