码迷,mamicode.com
首页 > 其他好文 > 详细

Codeforces Round #503 (by SIS, Div. 2) C. Elections

时间:2018-08-12 14:15:01      阅读:151      评论:0      收藏:0      [点我收藏+]

标签:ever   frame   ica   def   lan   ++   for   char   nim   

【题目描述】

    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\n",ans);
32     return 0;
33 }

 

Codeforces Round #503 (by SIS, Div. 2) C. Elections

标签:ever   frame   ica   def   lan   ++   for   char   nim   

原文地址:https://www.cnblogs.com/Willendless/p/9462356.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!