【题目描述】

    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. shell练习--PAT题目1002:写出这个数(失败案例)

    读入一个正整数 n,计算其各位数字之和,用汉语拼音写出和的每一位数字. 输入格式: 每个测试输入包含 1 个测试用例,即给出自然数 n 的值.这里保证 n 小于 1. 输出格式: 在一行内输出 n 的 ...

  2. 开发工具Intellij IDEA:面板介绍

    一.面板说明 IDEA面板的全貌如下图 2|0 二.菜单栏 下面会简单介绍下一些常用的部分菜单使用,如有疑问或补充欢迎留言. (1).File文件 1. New:新建一个工程 可以新建project, ...

  3. ipcloud上传裁切图片,保存为base64再压缩传给后台

    <!doctype html> <html> <head> <meta charset="utf-8"> <meta name ...

  4. 树状数组板子 x

    树状数组! 参考 http://www.cnblogs.com/zzyh/p/6992148.html 洛谷 P3374 [模板]树状数组 1 题目描述 如题,已知一个数列,你需要进行下面两种操作: ...

  5. [CF938E]Max History题解

    题面 >CF传送门< >洛谷传送门< 解法 显而易见,对于一个数\(a_i\),若果它出现在\(f\)序列中,必定\(a_i\)之前的元素要小于\(a_i\),我们设\(cnt ...

  6. encodeURIComponent()加密、decodeURIComponent()解码及v-html将字符串转换为html

    1)新闻详情页后台给我的数据是加密之后的,我问了后台,是用encodeURIComponent()加密的,然后我就用对应的方法decodeURIComponent()解密: this.$store.s ...

  7. SpringBoot属性配置-第三章

    1.application.yml配置#自定义参数对象book: name: A id: 1 page: 100 2.创建实体类: /** * @Auther: youqc * @Date: 2018 ...

  8. mysql中的collate关键字是什么意思?

    CREATE TABLE `tb_order` ( `order_id` varchar(50) COLLATE utf8_bin DEFAULT NULL COMMENT '订单id', `paym ...

  9. (转)oracle触发器使用:after insert 与before insert的简单使用注意

    本文转载自:http://blog.csdn.net/kuangfengbuyi/article/details/41446125 创建触发器时,触发器类型为after insert , 在begin ...

  10. ubuntu 安装 rocketmq

    1.安装 rocketmq首先要有java以及maven环境,这里略过,可参考 https://www.cnblogs.com/xiaobaoTribe/p/11315011.html  安装JDK ...