Elections CodeForces - 1020C (贪心)
大意: 有n个选民, m个党派, 第i个选民初始投$p_i$一票, 可以花费$c_i$改变投票, 求最少花费使得第一个党派的票数严格最大
假设最终第一个党派得票数$x$, 枚举$x$, 则对于所有票数$\ge x$的党派, 贪心选择尽量小的c改选第一个党派.若最后票数还不够, 再从没改过的人中选择尽量小的改选即可
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define pb push_back
#define x first
#define y second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii; const int N = 4e5+10, INF = 0x3f3f3f3f;
int n, m;
vector<pii> s[N];
pii a[N];
int vis[N]; int main() {
scanf("%d%d", &n, &m);
REP(i,1,n) {
int x, y;
scanf("%d%d", &x, &y);
s[x].pb({y,i});
a[i] = {x==1?1e9:y,i};
}
sort(a+1, a+1+n);
REP(i,2,m) sort(s[i].begin(),s[i].end());
ll ans = 1e18;
REP(i,1,n) {
int tot = 0;
ll c = 0;
REP(j,2,m) if (s[j].size()>=i) {
for (int k=0; k<=s[j].size()-i; ++k) {
++tot, c+=s[j][k].x, vis[s[j][k].y]=1;
}
}
REP(j,1,n) {
if (s[1].size()+tot<i&&!vis[a[j].y]) {
++tot, c+=a[j].x;
}
}
if (s[1].size()+tot==i) {
ans = min(ans, c);
}
REP(i,1,n) vis[i]=0;
}
printf("%lld\n", ans);
}
Elections CodeForces - 1020C (贪心)的更多相关文章
- Little Elephant and Elections CodeForces - 258B
Little Elephant and Elections CodeForces - 258B 题意:给出m,在1-m中先找出一个数x,再在剩下数中找出6个不同的数y1,...,y6,使得y1到y6中 ...
- CodeForces - 1020C C - Elections(贪心+枚举)
题目: 党派竞争投票 有n个人,m个党派,这n个人每个人有一个想要投的党派的编号Pi,如果想要这个人改变他的想法,那么就需要花费Ci元钱. 现在你是编号为1的党派,如果你想要赢(你的票数严格大于其他党 ...
- 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 respe ...
- CodeForces - 893D 贪心
http://codeforces.com/problemset/problem/893/D 题意 Recenlty Luba有一张信用卡可用,一开始金额为0,每天早上可以去充任意数量的钱.到了晚上, ...
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem D (Codeforces 831D) - 贪心 - 二分答案 - 动态规划
There are n people and k keys on a straight line. Every person wants to get to the office which is l ...
- Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) Problem D (Codeforces 828D) - 贪心
Arkady needs your help again! This time he decided to build his own high-speed Internet exchange poi ...
- CodeForces - 93B(贪心+vector<pair<int,double> >+double 的精度操作
题目链接:http://codeforces.com/problemset/problem/93/B B. End of Exams time limit per test 1 second memo ...
- C - Ordering Pizza CodeForces - 867C 贪心 经典
C - Ordering Pizza CodeForces - 867C C - Ordering Pizza 这个是最难的,一个贪心,很经典,但是我不会,早训结束看了题解才知道怎么贪心的. 这个是先 ...
- Codeforces 570C 贪心
题目:http://codeforces.com/contest/570/problem/C 题意:给你一个字符串,由‘.’和小写字母组成.把两个相邻的‘.’替换成一个‘.’,算一次变换.现在给你一些 ...
随机推荐
- 【翻唱】Keep On Fighting
http://video.yingtu.co/0/77868591-502c-4af1-853b-d313e83c94a9.mp4 Keep On Fighting
- Python入门之logging模块
本章目录: 一.logging模块简介 二.logging模块的使用 三.通过JSON或者YMAL文件配置logging模块 ===================================== ...
- MVC 扩展RadioButtonListFor和CheckBoxListFor
学习MVC时候前端通常会用到HtmlHelper,使得前端编码简便很多.我们可能会经常用到htmlHelper中一些的EditorFor,LabelFor,ValiationMessageFor, 发 ...
- 20145118 《Java程序设计》 实验报告三
实验三 敏捷开发与XP实践 实验内容 XP基础 XP核心实践 相关工具 实验要求 1.没有Linux基础的同学建议先学习<Linux基础入门(新版)><Vim编辑器> 课程 2 ...
- CmsEasy 5.5 cut_image 代码执行漏洞
3 CmsEasy 5.5 cut_image 代码执行漏洞 3.1 摘要 3.1.1 漏洞介绍 CmsEasy是一款基于PHP+MySQL架构的网站内容管理系统,可面向大中型站点提供重量级网站建设解 ...
- 20165211 学习基础和C语言调查
20165211 学习基础和C语言调查 理论脱离实践是最大的不幸.--达芬奇 达芬奇,是我眼里最有嫌疑的穿越者. 绘画.天文.雕塑.音乐.发明.建筑,数学.生理.物理.天文.地质--我很难想象有一个人 ...
- Python3基础 str endswith 是否以指定字符串结束
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- 如何在Twitter开发者平台上注册自己的应用
1.打开twitter的官网https://dev.twitter.com,如果还没有注册账号的,需要注册账号,已经注册账号的,请先登录:2.选择其中的My apps,如下图: 3.进去界面,选择Cr ...
- 详解一下 javascript 中的比较
翻译自:http://www.ecma-international.org/ecma-262/5.1/#sec-11.9.3 在JS中的关系比较(Relational Comparison)运算,指的 ...
- POJ 2104 K-th Number(主席树模板题)
http://poj.org/problem?id=2104 题意:求区间$[l,r]$的第k小. 思路:主席树不好理解啊,简单叙述一下吧. 主席树就是由多棵线段树组成的,对于数组$a[1,2...n ...