1020C Elections
题目大意
现在有 n个人,m个党派,第i个人开始想把票投给党派pi,而如果想让他改变他的想法需要花费ci元。你现在是党派1,问你最少花多少钱使得你的党派得票数大于其它任意党派。
分析
我们枚举i,表示除了自己之外的其它任何党派最多得票数不超过i,而我们每次只需要改变一个党派中需要花费的钱最少的那几个人就行了,在保证其它党派德比得票数都小于i之后如果自己党派的得票小于i,则不断改变需花费钱最少的那一个人的想法就行了。详见代码。
代码
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
#define li long long
const li inf = 1e18;
struct node {
int a;
li b;
};
node d[];
inline bool cmp(const node x,const node y){
return x.b<y.b;
}
int used[],tot[];
int main(){
int n,m,i,j,k;
scanf("%d%d",&n,&m);
for(i=;i<=n;i++){
scanf("%d%lld",&d[i].a,&d[i].b);
}
sort(d+,d+n+,cmp);
li ans=inf;
for(i=;i<=n;i++){
memset(used,,sizeof(used));
memset(tot,,sizeof(tot));
li sum=;
for(j=n;j>;j--)
if(d[j].a!=){
if(tot[d[j].a]+>=i){
tot[]++;
used[j]=;
sum+=d[j].b;
}else {
tot[d[j].a]++;
}
}else {
tot[]++;
used[j]=;
}
for(j=;j<=n;j++)
if(!used[j]&&tot[]<i){
tot[]++;
sum+=d[j].b;
}
if(tot[]>=i)ans=min(ans,sum);
}
cout<<ans<<endl;
return ;
}
1020C Elections的更多相关文章
- Elections CodeForces - 1020C (贪心)
大意: 有n个选民, m个党派, 第i个选民初始投$p_i$一票, 可以花费$c_i$改变投票, 求最少花费使得第一个党派的票数严格最大 假设最终第一个党派得票数$x$, 枚举$x$, 则对于所有票数 ...
- CodeForces - 1020C C - Elections(贪心+枚举)
题目: 党派竞争投票 有n个人,m个党派,这n个人每个人有一个想要投的党派的编号Pi,如果想要这个人改变他的想法,那么就需要花费Ci元钱. 现在你是编号为1的党派,如果你想要赢(你的票数严格大于其他党 ...
- Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2) A. Bear and Elections 优先队列
A. Bear and Elections ...
- CF 369C . Valera and Elections tree dfs 好题
C. Valera and Elections The city Valera lives in is going to hold elections to the city Parliament ...
- 【CF850E】Random Elections(FWT)
[CF850E]Random Elections(FWT) 题面 洛谷 CF 题解 看懂题就是一眼题了... 显然三个人是等价的,所以只需要考虑一个人赢了另外两个人就好了. 那么在赢另外两个人的过程中 ...
- Codeforces 458C - Elections
458C - Elections 思路: 三分凹形函数极小值域 代码: #include<bits/stdc++.h> using namespace std; #define ll lo ...
- 【CF850E】Random Elections FWT
[CF850E]Random Elections 题意:有n位选民和3位预选者A,B,C,每个选民的投票方案可能是ABC,ACB,BAC...,即一个A,B,C的排列.现在进行三次比较,A-B,B-C ...
- CodeForces - 369C - Valera and Elections
369C - Valera and Elections 思路:dfs,对于搜索到的每个节点,看他后面有没有需要修的路,如果没有,那么这个节点就是答案. 代码: #include<bits/std ...
- CodeForces - 457C:Elections(三分)
You are running for a governor in a small city in Russia. You ran some polls and did some research, ...
随机推荐
- RTP协议全解(H264码流和PS流)
写在前面:RTP的解析,网上找了很多资料,但是都不全,所以我力图整理出一个比较全面的解析, 其中借鉴了很多文章,我都列在了文章最后,在此表示感谢. 互联网的发展离不开大家的无私奉献,我决定从我做起,希 ...
- matrix-gui-2.0 将javascript文件夹改成js文件夹
/******************************************************************************** * matrix-gui-2.0 将 ...
- MySql数据库约束
<MySQL技术内幕:InnoDB存储引擎>本书从源代码的角度深度解析了InnoDB的体系结构.实现原理.工作机制,并给出了大量实践,本着将书读薄的思想,循序渐进的记录对本书学习的读书笔记 ...
- BZOJ4808: 马
BZOJ4808: 马 https://lydsy.com/JudgeOnline/problem.php?id=4808 分析: 黑白染色,求二分图最大匹配即可. 代码: #include < ...
- LeetCode 369. Plus One Linked List
原题链接在这里:https://leetcode.com/problems/plus-one-linked-list/ 题目: Given a non-negative number represen ...
- vmem驱动设备
vmem是内存多字符设备.包含vfs的open.read.write.ioctl.poll.fasync和release函数,device文件的读写. virtual_mem.c #include & ...
- bzoj 3028 食物——生成函数
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3028 把式子写出来,化一化,变成 x / ((1-x)^4) ,变成几个 sigma 相乘的 ...
- Poj 1631 Bridging signals(二分+DP 解 LIS)
题意:题目很难懂,题意很简单,求最长递增子序列LIS. 分析:本题的最大数据40000,多个case.用基础的O(N^2)动态规划求解是超时,采用O(n*log2n)的二分查找加速的改进型DP后AC了 ...
- 在Mac系统下使用自己安装的PHP
今天在安装单元测试框架PHPUnit,需要PHP的最低版本是5.6,由于我的MacBook自带的PHP版本是5.5.36,不能满足安装条件. 看了一下这个网址:https://php-osx.liip ...
- el表达式对js方法的传值
我常用于在jsp页面遍历集合和分页中的页面跳转事件. jsp: <!-- 引入jstl --> <%@ taglib prefix="c" uri="h ...