连接:http://codeforces.com/contest/1020

C.Elections

题型:你们说水题就水题吧...我没有做出来...get到了新的思路,不虚。好像还有用三分做的?

KN Point(注意复杂度性能):优先队列1优先队列2

 #include<bits/stdc++.h>
using namespace std;
#define ll long long
const int inf=3e3+;
priority_queue<int,vector<int>,greater<int> >tep[inf],s[inf],S; //优先队列
ll ans=1e18;
int main()
{
ios::sync_with_stdio();
int n,m;
cin>>n>>m;
for(int i=;i<=n;i++)
{
int c,p;
cin>>c>>p;
s[c].push(p);
}
for(int i=;i<=n;i++) //索性枚举所有胜出可能需要拥有的票数,就不用考虑到底到底贿赂谁了
{
ll v=;int cnt=s[].size();
while(!S.empty()) S.pop();
for(int j=;j<=m;j++) tep[j]=s[j]; for(int j=;j<=m;j++) //复杂度不会算了,有没有人教一下,感觉整个程序的复杂度在 n^2*log(n)左右
while(tep[j].size()>=i)
v+=tep[j].top(),tep[j].pop(),cnt++; //让所有除1以外的所有人需要减掉的票数
for(int j=;j<=m;j++)
while(!tep[j].empty())
S.push(tep[j].top()),tep[j].pop(); //存下剩下的票数
while(cnt<i&&!S.empty())
cnt++,v+=S.top(),S.pop(); //用剩下的票数使得1的票数大于等于所需要的票数
if(cnt>=i) ans=min(ans,v);
}
cout<<ans<<endl;
}

Codeforces Round #503 (by SIS, Div. 2)的更多相关文章

  1. 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 ...

  2. 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 respe ...

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

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

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

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

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

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

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

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

  7. 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 ...

  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. 三报文握手 四报文握手 TCP运输连接管理

    三报文握手 四报文握手  TCP运输连接管理

  2. Jmeter正则表达式提取器

    https://www.cnblogs.com/tudou-22/p/9566894.html Jmeter中关联是通过“添加—后置处理器—正则表达式提取器”来获取数据 一.获取单个数据

  3. 解决 warning I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2

    只需要加载如下代码: import os os.environ['

  4. vue 子组件调用父组件的方法

    vue中 父子组件的通信: 子组件通过 props: { //子组件中写的. childMsg: { //字段名 type: Array,//类型 default: [0,0,0] //这样可以指定默 ...

  5. Spark入门到精通--(第十节)环境搭建(ZooKeeper和kafka搭建)

    上一节搭建完了Hive,这一节我们来搭建ZooKeeper,主要是后面的kafka需要运行在上面. ZooKeeper下载和安装 下载ZooKeeper 3.4.5软件包,可以在百度网盘进行下载.链接 ...

  6. python练习题-day26

    #bim(property) class People: def __init__(self,name,weight,height): self.name=name self.weight=weigh ...

  7. Uva 12009 平方数尾数与自身同样 dfs 构造

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/qq574857122/article/details/25166611 题目链接:点击打开链接 题意 ...

  8. extjs 跨域 ajax.request

    https://www.cnblogs.com/yuzhongwusan/p/3677955.html https://stackoverflow.com/questions/25727306/req ...

  9. windows10中修改环境变量的正确姿势

    提到修改环境变量,我们可能自然而然想到:右键This PC->Properties->Advanced System Settings->Environment Variables ...

  10. 再谈HTTP2性能提升之背后原理—HTTP2历史解剖

    即使千辛万苦,还是把网站升级到http2了,遇坑如<phpcms v9站http升级到https加http2遇到到坑>. 因为理论相比于 HTTP 1.x ,在同时兼容 HTTP/1.1 ...