【题目描述】

    Elections are coming. You know the number of voters and the number of parties — n and m respectively. For each voter you know the party he is going to vote for. However, he can easily change his vote given a certain amount of money. In particular, if you give i-th voter ci bytecoins you can ask him to vote for any other party you choose.

    The United Party of Berland has decided to perform a statistical study — you need to calculate the minimum number of bytecoins the Party needs to spend to ensure its victory. In order for a party to win the elections, it needs to receive strictly more votes than any other party.、

【题目链接】

    http://codeforces.com/contest/1020/problem/C

【算法】

    枚举答案(一号政党最终(至少)的选民数x),其它政党则最终选民数至多为x-1,贪心选取贿赂者。若一号政党仍不足x人,则从剩下的选民中贪心的取。

    思想类似的题目:1、(钓鱼)https://loj.ac/problem/10009 (暴力+贪心) 2、朴素的环形均分纸牌(暴力枚举环的断点)

【代码】暴力最终选民数

 #include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
int n,m,tot;
ll ans=LLONG_MAX;
vector<int> party[];
int rec[];
int main()
{
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++) {
int p,c; scanf("%d%d",&p,&c);
party[p].pb(c);
}
for(int i=;i<=m;i++) sort(party[i].begin(),party[i].end());
for(int i=max(,(int)party[].size());i<=n;i++) {
int cur=party[].size(); ll cost=;
tot=;
for(int j=;j<=m;j++) {
int k;
for(k=party[j].size();k>=i;k--) cost+=party[j][party[j].size()-k],cur++;
for(k=party[j].size()-k;k<party[j].size();k++) rec[++tot]=party[j][k];
}
if(cur<i) {
sort(rec+,rec+tot+);
for(int k=;k<=tot&&cur<i;k++) cost+=rec[k],cur++;
}
ans=min(ans,cost);
}
printf("%I64d\n",ans);
return ;
}

【钓鱼】暴力最终到达的鱼塘

 #include <bits/stdc++.h>
using namespace std;
int n,H,ans;
int b[],dx[],t[];
int main()
{
scanf("%d%d",&n,&H); H=H*/;
for(int i=;i<=n;i++) scanf("%d",&b[i]);
for(int i=;i<=n;i++) scanf("%d",&dx[i]);
for(int i=;i<=n;i++) scanf("%d",&t[i]),t[i]+=t[i-];
for(int i=;i<=n;i++) {
int cur=; priority_queue< pair<int,int> > pq;
for(int j=;j<=i;j++) pq.push(make_pair(b[j],dx[j]));
int T=H-t[i];
while(pq.top().first>&&T>) {
cur+=pq.top().first; T--;
pair<int,int> p=pq.top(); pq.pop();
p.first-=p.second; pq.push(p);
}
ans=max(ans,cur);
}
printf("%d\n",ans);
return ;
}

Codeforces Round #503 (by SIS, Div. 2) C. Elections (暴力+贪心)的更多相关文章

  1. Codeforces Round #503 (by SIS, Div. 2)-C. Elections

    枚举每个获胜的可能的票数+按照花费排序 #include<iostream> #include<stdio.h> #include<string.h> #inclu ...

  2. Codeforces Round #503 (by SIS, Div. 2) C. Elections(枚举,暴力)

    原文地址 C. Elections time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  3. Codeforces Round #503 (by SIS, Div. 2) Solution

    从这里开始 题目列表 瞎扯 Problem A New Building for SIS Problem B Badge Problem C Elections Problem D The hat P ...

  4. Codeforces Round #503 (by SIS, Div. 2)

    连接:http://codeforces.com/contest/1020 C.Elections 题型:你们说水题就水题吧...我没有做出来...get到了新的思路,不虚.好像还有用三分做的? KN ...

  5. Codeforces Round #503 (by SIS, Div. 1)E. Raining season

    题意:给一棵树每条边有a,b两个值,给你一个m,表示从0到m-1,假设当前为i,那么每条边的权值是a*i+b,求该树任意两点的最大权值 题解:首先我们需要维护出(a,b)的凸壳,对于每个i在上面三分即 ...

  6. Codeforces Round #503 (by SIS, Div. 2) D. The hat

    有图可以直观发现,如果一开始的pair(1,1+n/2)和pair(x, x+n/2)大小关系不同 那么中间必然存在一个答案 简单总结就是大小关系不同,中间就有答案 所以就可以使用二分 #includ ...

  7. Codeforces Round #503 (by SIS, Div. 2)B 1020B Badge (拓扑)

    题目大意:每个同学可以指定一个人,然后构成一个有向图.1-n次查询,从某个人开始并放入一个东西,然后循环,直到碰到一个人已经放过了,就输出. 思路:直接模拟就可以了,O(n^2) 但是O(n)也可以实 ...

  8. Codeforces Round #503 (by SIS, Div. 2) D. The hat -交互题,二分

    cf1020D 题意: 交互题目,在有限的询问中找到一个x,使得数列中的第x位和第(x+n/2)位的值大小相同.数列保证相邻的两个差值为1或-1: 思路: 构造函数f(x) = a[x] - a[x ...

  9. Codeforces Round #503 (by SIS, Div. 2) E. Sergey's problem

    E. Sergey's problem [题目描述] 给出一个n个点m条边的有向图,需要找到一个集合使得1.集合中的各点之间无无边相连2.集合外的点到集合内的点的最小距离小于等于2. [算法] 官方题 ...

随机推荐

  1. delphi 10.3.1 android沉浸式透明状态栏

    从10.2升级上来, 之前的沉浸状态栏在android手机上不透明了, 添加二个发布文件,remote path分别设为 res\values-v21和 res\values-v19 style.xm ...

  2. Python3 三元表达式、列表推导式、生成器表达式

    Python3 三元表达式.列表推导式.生成器表达式 三元表达式 表达式中,有三个元素 name = input("请输入姓名: ")ret = '输入正确' if name == ...

  3. CF F. Royal Questions kruskal

    每一个 $A$ 必须和指定的唯一的 $B$ 匹配,转化成图论关系就是 $A$ 和 $B$ 之间有若干条连边,每个边有一个边权,而该边权只能代表一对 $A,B$. 这其实就是一个基环树的结构. 所以只需 ...

  4. jQuery插件simplePagination的使用-踩坑记_03

    jQuery插件simplePagination的使用 正在熟悉项目上的代码,新添加了一个需要,需要对表单进行分页,之前的代码中是有分页的代码的,看了老半天,也没看太明白.之前的项目比较久远,继续熟悉 ...

  5. Django学习之视图

    一.Django的View(视图) 1.一个简单的视图 3.CBV和FBV 4.给视图加装饰器 使用装饰器装饰FBV 使用装饰器装饰CBV 二.Request对象和Response对象 1.reque ...

  6. Delphi XE2 之 FireMonkey 入门(26) - 数据绑定: TBindingsList: TBindExprItems

    Delphi XE2 之 FireMonkey 入门(26) - 数据绑定: TBindingsList: TBindExprItems 如果要给一对 "源控件" 和 " ...

  7. JMeter Gui – TestElement约定(转自约会言行的博客,链接:http://blog.csdn.net/yue530tomtom/article/details/77649872?locationNum=4&fps=1)

    在编写任何JMeter组件时,必须注意某些特定的约定——如果JMeter环境中正确地运行JMeter组件,那么它将会运行.本部分描述了组件的GUI部分必须满足的约定. JMeter中的GUI代码严格地 ...

  8. C++中的通用结构定义,及相应的序列化、反序列化接口

    一个通用的C++结构定义如下: typedef struct tagCommonStruct { long len; void* buff; }CommonStruct_st; 此接口对应的普通序列化 ...

  9. django-xadmin设置全局变量

    class GlobalSetting(object): site_title = '自己的命名' site_footer = '底部命名'# 收缩菜单 menu_style = 'accordion ...

  10. Linux(Ubuntu)常用命令(三)

    查看时间  cal :显示当前日期.  cal :显示全年日历./ cal -y 显示当年日历.  date :显示当前时间. 这几个一般不会用到了解即可. 查看进程信息  ps :显示当前进程. - ...