传送门

题目大意

现在有 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的更多相关文章

  1. Elections CodeForces - 1020C (贪心)

    大意: 有n个选民, m个党派, 第i个选民初始投$p_i$一票, 可以花费$c_i$改变投票, 求最少花费使得第一个党派的票数严格最大 假设最终第一个党派得票数$x$, 枚举$x$, 则对于所有票数 ...

  2. CodeForces - 1020C C - Elections(贪心+枚举)

    题目: 党派竞争投票 有n个人,m个党派,这n个人每个人有一个想要投的党派的编号Pi,如果想要这个人改变他的想法,那么就需要花费Ci元钱. 现在你是编号为1的党派,如果你想要赢(你的票数严格大于其他党 ...

  3. Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2) A. Bear and Elections 优先队列

                                                    A. Bear and Elections                               ...

  4. 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 ...

  5. 【CF850E】Random Elections(FWT)

    [CF850E]Random Elections(FWT) 题面 洛谷 CF 题解 看懂题就是一眼题了... 显然三个人是等价的,所以只需要考虑一个人赢了另外两个人就好了. 那么在赢另外两个人的过程中 ...

  6. Codeforces 458C - Elections

    458C - Elections 思路: 三分凹形函数极小值域 代码: #include<bits/stdc++.h> using namespace std; #define ll lo ...

  7. 【CF850E】Random Elections FWT

    [CF850E]Random Elections 题意:有n位选民和3位预选者A,B,C,每个选民的投票方案可能是ABC,ACB,BAC...,即一个A,B,C的排列.现在进行三次比较,A-B,B-C ...

  8. CodeForces - 369C - Valera and Elections

    369C - Valera and Elections 思路:dfs,对于搜索到的每个节点,看他后面有没有需要修的路,如果没有,那么这个节点就是答案. 代码: #include<bits/std ...

  9. CodeForces - 457C:Elections(三分)

    You are running for a governor in a small city in Russia. You ran some polls and did some research, ...

随机推荐

  1. New Concept English three (49)

    31w/m 51error It is a good thing my aunt Harriet died years ago. If she were alive today she would n ...

  2. HDU 5776

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5776 求是否有区间的和是m的倍数 预处理前缀和,一旦有两个数模m的值相同,说明中间一部分连续子列可以组 ...

  3. cut---Linux下文本处理五大神器之四

    转自:http://www.cnblogs.com/dong008259/archive/2011/12/09/2282679.html cut是一个选取命令,就是将一段数据经过分析,取出我们想要的. ...

  4. 洛谷 P3052 [USACO12MAR]摩天大楼里的奶牛Cows in a Skyscraper

    题目描述 A little known fact about Bessie and friends is that they love stair climbing races. A better k ...

  5. 用TCP穿透NAT(TCP打洞)的实现

    目录 TCP穿透原理 程序思路 声明 上代码 运行示例 1. TCP穿透原理: 我们假设在两个不同的局域网后面分别有2台客户机A和 B,AB所在的局域网都分别通过一个路由器接入互联网.互联网上有一台服 ...

  6. ORACLE删除用户的有的表的方法

    首先我们查询oracle用户下的所有表 select * from all_tab_comments -- 查询所有用户的表,视图等select * from user_tab_comments    ...

  7. 使用Jsonp实现跨域请求

    来自百度百科的一段话: JSONP(JSON with Padding)是JSON的一种“使用模式”,可用于解决主流浏览器的跨域数据访问的问题.由于同源策略,一般来说位于 server1.exampl ...

  8. Python学习笔记 - PostgreSQL的使用

    一.安装PostgreSQL模块 pip install psycopg2 有时候会失败,多安装2次就好了(我是第二次成功了). 二.数据库连接接口 由于Python统一了数据库连接的接口,所以psy ...

  9. 机器学习:SVM(基础理解)

    一.基础理解 1)简介 SVM(Support Vector Machine):支撑向量机,既可以解决分类问题,又可以解决回归问题: SVM 算法可分为:Hard Margin SVM.Soft Ma ...

  10. Python:序列的copy() 方法和 copy 模块

    转于:Python中copy和deepcopy中的区别 博主:assan 一.序列中的 copy() 方法 # 此方法为浅度复制:复制的数会随着被复制数的嵌套序列的元素的改变而改变: # 功能:将一个 ...