传送门

题目大意

现在有 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. 去掉Arraylist集合中的重复元素

    package cn.collection; import java.util.ArrayList; import java.util.Iterator; import java.util.Scann ...

  2. List集合添加自定义对象

    public class Student { private String name; private int age; public Student() { super(); } public St ...

  3. L124

    I have a toothache because there is a cavity in one of my teeth. I founded an orphanage last year an ...

  4. python list的extend和append方法

    append: Appends object at the end. x = [1, 2, 3] x.append([4, 5]) print (x) gives you: [1, 2, 3, [4, ...

  5. nginx负载均衡的简单实现

    负载均衡是我们大流量网站要做的一个东西,下面我来给大家介绍在Nginx服务器上进行负载均衡配置方法,希望对有需要的同学有所帮助哦. 负载均衡 先来简单了解一下什么是负载均衡,单从字面上的意思来理解就可 ...

  6. Swap Adjacent Elements

    You have an array a consisting of n integers. Each integer from 1 to n appears exactly once in this ...

  7. 【LeetCode】008. String to Integer (atoi)

    Implement atoi to convert a string to an integer. Hint: Carefully consider all possible input cases. ...

  8. Unity 头发随动效果

    目标 实现角色的衣袖.头发.裙摆.披风.尾巴等,在角色运动时,可以产生随动的效果.类似王者荣耀角色展示界面. 准备 源码出出处:https://github.com/unity3d-jp/unityc ...

  9. PCBA 生产需要什么文件? (2018-07-10)

    PCBA 生产需要什么文件? 生产需要资料 工单套料单 生产说明文件 生产贴片图 正面含元件号 背面含元件号 钢网资料(可以是 Gerber) 元件坐标图

  10. js易犯错误与易混淆的重要知识点

    一:作用域的问题 简单案例1: var a = 1; var n = function () { console.log(a); var a=2; } n(); =>输出undefined原因: ...