Codeforces Round #503 (by SIS, Div. 2) C. Elections (暴力+贪心)
【题目描述】
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 (暴力+贪心)的更多相关文章
- Codeforces Round #503 (by SIS, Div. 2)-C. Elections
枚举每个获胜的可能的票数+按照花费排序 #include<iostream> #include<stdio.h> #include<string.h> #inclu ...
- 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 ...
- 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 ...
- Codeforces Round #503 (by SIS, Div. 2)
连接:http://codeforces.com/contest/1020 C.Elections 题型:你们说水题就水题吧...我没有做出来...get到了新的思路,不虚.好像还有用三分做的? KN ...
- Codeforces Round #503 (by SIS, Div. 1)E. Raining season
题意:给一棵树每条边有a,b两个值,给你一个m,表示从0到m-1,假设当前为i,那么每条边的权值是a*i+b,求该树任意两点的最大权值 题解:首先我们需要维护出(a,b)的凸壳,对于每个i在上面三分即 ...
- Codeforces Round #503 (by SIS, Div. 2) D. The hat
有图可以直观发现,如果一开始的pair(1,1+n/2)和pair(x, x+n/2)大小关系不同 那么中间必然存在一个答案 简单总结就是大小关系不同,中间就有答案 所以就可以使用二分 #includ ...
- Codeforces Round #503 (by SIS, Div. 2)B 1020B Badge (拓扑)
题目大意:每个同学可以指定一个人,然后构成一个有向图.1-n次查询,从某个人开始并放入一个东西,然后循环,直到碰到一个人已经放过了,就输出. 思路:直接模拟就可以了,O(n^2) 但是O(n)也可以实 ...
- Codeforces Round #503 (by SIS, Div. 2) D. The hat -交互题,二分
cf1020D 题意: 交互题目,在有限的询问中找到一个x,使得数列中的第x位和第(x+n/2)位的值大小相同.数列保证相邻的两个差值为1或-1: 思路: 构造函数f(x) = a[x] - a[x ...
- Codeforces Round #503 (by SIS, Div. 2) E. Sergey's problem
E. Sergey's problem [题目描述] 给出一个n个点m条边的有向图,需要找到一个集合使得1.集合中的各点之间无无边相连2.集合外的点到集合内的点的最小距离小于等于2. [算法] 官方题 ...
随机推荐
- 查看jar包内容
查看jar包内容 查看jar包内容的基本命令: jar tf jar-file 参数解释: The t option indicates that you want to view the table ...
- java伪代码读后感
愚公,在这位名家身上,浓缩了项目的组织者,团队经理,编程人员,技术分析师等众多角色的优秀素质.原始需求的产生“惩山北之塞,出入之迁”项目沟通的基本方式“聚室而谋之”项目的目标“毕力平险,指通豫南,达于 ...
- PHP文件的上传和下载
1.使用PHP的创始人 Rasmus Lerdorf 写的APC扩展模块来实现(http://pecl.php.net/package/apc) APC实现方法: 安装APC,参照官方文档安装,可以使 ...
- 01 Netty是什么?
01 Netty是什么? IO编程 我们简化下场景:客户端每隔两秒发送一个带有时间戳的 "hello world" 给服务端,服务端收到之后打印. 为了方便演示,下面例子中,服务端 ...
- 解决RHEL6 vncserver 启动 could not open default font 'fixed'错误.
https://blog.csdn.net/silencegll/article/details/51320629
- java创建对象方法列表
引用 不用构造方法也能创建对象 前言 java中对象创建的方法主要包括,1,使用new关键字,2.使用clone方法,3.反射机制,4.反序列化.其中1,3都会明确的显式的调用构造函数.2是在内存上对 ...
- MacOS X 安装OpenCV3.2
windows平台和linux平台安装参见 官方文档:http://docs.opencv.org/3.2.0/da/df6/tutorial_py_table_of_contents_setup.h ...
- Linux驱动开发7——I/O内存分配
CPU通过物理地址访问DDR和外设,DDR内存称为物理内存地址空间,外设寄存器组称为I/O内存地址空间. ARM采用统一编址,而X86采用独立编制.上一章介绍了DDR内存分配,这一章介绍I/O内存分配 ...
- VS Project Property Manage
概念:Project Property 和 Property Sheet. Project Property:项目属性,是你当前项目的属性配制,保存在你工程的配制文件中,rojectName.vcxp ...
- ceph-pve英语
adapted accordingly并相应地调整 silosn. 筒仓:粮仓:贮仓(silo的复数) saturatevt. 浸透,使湿透:使饱和,使充满While one HDD might no ...