Codeforces Round #503 (by SIS, Div. 2) C. Elections
Posted willendless
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces Round #503 (by SIS, Div. 2) C. Elections相关的知识,希望对你有一定的参考价值。
【题目描述】
Elections are coming. You know the number of voters and the number of parties — n and m respectively. For each voter you know the party he is going to vote for. However, he can easily change his vote given a certain amount of money. In particular, if you give i-th voter ci bytecoins you can ask him to vote for any other party you choose.
The United Party of Berland has decided to perform a statistical study — you need to calculate the minimum number of bytecoins the Party needs to spend to ensure its victory. In order for a party to win the elections, it needs to receive strictly more votes than any other party.、
【题目链接】
http://codeforces.com/contest/1020/problem/C
【算法】
枚举答案,贪心选取投票者。
【代码】
1 #include <bits/stdc++.h> 2 #define ll long long 3 #define pb push_back 4 using namespace std; 5 int n,m,tot; 6 ll ans=LLONG_MAX; 7 vector<int> party[3010]; 8 int rec[3010]; 9 int main() 10 { 11 scanf("%d%d",&n,&m); 12 for(int i=1;i<=n;i++) { 13 int p,c; scanf("%d%d",&p,&c); 14 party[p].pb(c); 15 } 16 for(int i=1;i<=m;i++) sort(party[i].begin(),party[i].end()); 17 for(int i=max(1,(int)party[1].size());i<=n;i++) { 18 int cur=party[1].size(); ll cost=0; 19 tot=0; 20 for(int j=2;j<=m;j++) { 21 int k; 22 for(k=party[j].size();k>=i;k--) cost+=party[j][party[j].size()-k],cur++; 23 for(k=party[j].size()-k;k<party[j].size();k++) rec[++tot]=party[j][k]; 24 } 25 if(cur<i) { 26 sort(rec+1,rec+tot+1); 27 for(int k=1;k<=tot&&cur<i;k++) cost+=rec[k],cur++; 28 } 29 ans=min(ans,cost); 30 } 31 printf("%I64d ",ans); 32 return 0; 33 }
以上是关于Codeforces Round #503 (by SIS, Div. 2) C. Elections的主要内容,如果未能解决你的问题,请参考以下文章
Codeforces Round #503 (by SIS, Div. 2) C. Elections
Codeforces Round #503 (by SIS, Div. 2)
Codeforces Round #503 (by SIS, Div. 2)-C. Elections
Codeforces Round #503 (by SIS, Div. 2) Partial Solution