题意:

有 n个人,m个党派,第i个人开始想把票投给党派pi,而如果想让他改变他的想法需要花费ci元。你现在是党派1,问你最少花多少钱使得你的党派得票数大于其它任意党派。

n,m<3000

思路:

枚举“除了党派1之外其他党派最多有的票的数量”,贪心一下即可

坑点:

1.爆int

2.inf太小,要设成0x3f3f3f3f3f3f3f3f

3.sort忘了从第一个开始排(被Wa7支配)

#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<vector>
#include<map>
#include<functional>
#include<list> #define fst first
#define sc second
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,root<<1
#define rson mid+1,r,root<<1|1
#define lc root<<1
#define rc root<<1|1
#define lowbit(x) ((x)&(-x))
#pragma Gcc optimize(2) using namespace std; typedef double db;
typedef long double ldb;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PI;
typedef pair<ll,ll> PLL; const int maxn = + ;
const int maxm = 5e3 + ;
const double eps = 1e-;
const int inf = 0x3f3f3f3f;
const double pi = acos(-1.0);
int scan(){
int res=,ch,flag=;
if((ch=getchar())=='-')
flag=;
else if(ch>=''&&ch<='')
res=ch-'';
while((ch=getchar())>=''&&ch<='')
res=res*+ch-'';
return flag?-res:res;
}
//int vis[maxn];
struct vt{
int id;
int p;
ll c;
}v[maxn];
int num[maxn];
int cnt[maxn];
int vis[maxn];
/*bool cmp(vt a, vt b){
if(a.p==1)return false;
if(b.p==1)return true;
if(num[a.id] == num[b.id]){
return a.c < b.c;
}
else return num[a.id]<num[b.id];
}*/
bool cmp(vt a, vt b){
if(a.p==)return false;
if(b.p==)return true;
return a.c < b.c;
}
int main(){
int n, m;
scanf("%d %d", &n, &m);
//mem(vis, 0);
mem(num, );
for(int i = ; i <= n; i++){
int p, c;
scanf("%d %lld",&v[i].p, &v[i].c);
v[i].id = i;
num[v[i].p]++; }
ll ans = 0x3f3f3f3f3f3f3f3f;
sort(v+, v++n, cmp);
for(int i = ; i < n; i++){
ll tmp = ;
mem(vis, );
for(int j = ; j <= m ;j++){
cnt[j] = num[j];
}
for(int j = ; j <= n && v[j].p != ; j++){
if(cnt[v[j].p] > i){
cnt[]++;
cnt[v[j].p]--;
tmp += v[j].c;
vis[j] = ;
} }
if(cnt[] <= i){
for(int j = ; j <= n; j++ ){
if(cnt[]>i)break;
if(!vis[j]){
tmp += v[j].c;
cnt[]++;
}
}
}
if(cnt[]>=i)ans = min(tmp, ans);
//printf("%lld %d\n", tmp, cnt[1]);
}
printf("%lld", ans);
return ;
}

codeforces 1020 C Elections(枚举+贪心)的更多相关文章

  1. Codeforces #503 C. Elections(贪心,逆向

    我的参考的博客地址 题目 逆向考虑. 暴力遍历 k(k是1到n/2+1 范围内的),挑出对于每一个k,记对于党派 i,num[ i ]为其票数.num[ i ]小于k-1的就不用改变投票了(这部分是比 ...

  2. Codeforces C. Elections(贪心枚举三分)

    题目描述: C. Elections time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  3. D. Diverse Garland Codeforces Round #535 (Div. 3) 暴力枚举+贪心

    D. Diverse Garland time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  4. codeforces Gym 100338E Numbers (贪心,实现)

    题目:http://codeforces.com/gym/100338/attachments 贪心,每次枚举10的i次幂,除k后取余数r在用k-r补在10的幂上作为候选答案. #include< ...

  5. [Codeforces 1214A]Optimal Currency Exchange(贪心)

    [Codeforces 1214A]Optimal Currency Exchange(贪心) 题面 题面较长,略 分析 这个A题稍微有点思维难度,比赛的时候被孙了一下 贪心的思路是,我们换面值越小的 ...

  6. 51nod1625(枚举&贪心)

    题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1625 题意:中文题诶- 思路:枚举+贪心 一开始写的行和列同时 ...

  7. 枚举+贪心 HDOJ 4932 Miaomiao's Geometry

    题目传送门 /* 题意:有n个点,用相同的线段去覆盖,当点在线段的端点才行,还有线段之间不相交 枚举+贪心:有坑点是两个点在同时一条线段的两个端点上,枚举两点之间的距离或者距离一半,尽量往左边放,否则 ...

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

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

  9. codeforces 613B B. Skills(枚举+二分+贪心)

    题目链接: B. Skills time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

随机推荐

  1. caffe实战笔记

    Caffe简要介绍: Caffe还没有windows版本,所以我需要远程登录linux服务器 Caffe主要处理图片/图片序列 Caffe读取的数据格式 从专用的数据库中读取(lmdb.leveldb ...

  2. 解决:'chromedriver' executable needs to be in PATH的问题

    0.前言 今天写一个B站登录的模拟器时,用到了Chrome浏览器,但是会报了一个异常"'chromedriver' executable needs to be in PATH", ...

  3. BFS - 求最短路径

    Farmer John has been informed of the location of a fugitive cow and wants to catch her immediately. ...

  4. hive 动态分区

    非常重要的动态分区属性: hive.exec.dynamic.partition  是否启动动态分区.false(不开启) true(开启)默认是 false hive.exec.dynamic.pa ...

  5. doT 这个模板 是怎么实现的?(1)

  6. 个人第四次作业——Alpha测试

    Alpha项目测试 这个作业属于哪个课程 链接 这个作业要求在哪里 链接 团队名称 愿头发与你我同在 这个作业的目标 测试非本组的另外三组项目 姓名 张伟 学号 201731024216 测试报告 一 ...

  7. SpringBoot初级知识总结,太难了,未完待续.......

    idea如何打包发布springboot 1.1.环境准备window系统,jdk8环境,springboot项目,maven3.5.4环境 1.2.进行打包发布 打开idea编辑器,打开一个写好的d ...

  8. CentOS7下部署2套Python版本共存

    参考地址:https://www.cnblogs.com/xuaijun/p/7985245.html 源码的安装一般由3个步骤组成:配置(configure).编译(make).安装(make in ...

  9. P4452 [国家集训队]航班安排(最大费用最大流)

    P4452 [国家集训队]航班安排 题目传送门 解题思路: 感觉题面让人有很多误解,就是说有k架飞机在0点从0号机场起飞,在t时刻返回机场,给出空载飞行的时间和花费以及m个包机请求的花费和起始时间和终 ...

  10. 自动化运维之Ansible入门

    Ansible简介 Ansible是什么? Ansible 简单的说是一个配置管理系统(ConfiGuration Management System).你只需要可以使用ssh访问你的服务器或设备.它 ...