Codeforces Round #503 (by SIS, Div. 2)
连接:http://codeforces.com/contest/1020
C.Elections
题型:你们说水题就水题吧...我没有做出来...get到了新的思路,不虚。好像还有用三分做的?
#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)的更多相关文章
- 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) C. Elections (暴力+贪心)
[题目描述] Elections are coming. You know the number of voters and the number of parties — n and m respe ...
- Codeforces Round #503 (by SIS, Div. 2)-C. Elections
枚举每个获胜的可能的票数+按照花费排序 #include<iostream> #include<stdio.h> #include<string.h> #inclu ...
- 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) 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) 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. [算法] 官方题 ...
随机推荐
- SVN百度云服务器安装使用。
安装SVN客户端 此时,必须重启,否则经常出现用不了. 重启后,还是用不了的话,那么就重新安装系统. 网站地址: http://xiaomosheng.bceapp.com/ SVN代码服务器的地址: ...
- (转)手工释放linux内存——/proc/sys/vm/drop_cache
linux的内存查看: [root@localhost 0.1.0]# free -m total used free shared ...
- java实验一总结
实验一第一部分 在Linux中运行结果 通过cd和mkdir命令建立tree,带包编译并用 javac -d bin 的命令将编译文件保存在bin目录中 通过 java -cp 的命令运行带包的程序 ...
- B. Lynyrd Skynyrd
传送门: 题意:给出 n,m,q 然后给出模板串,从1-n数字只出现一次,然后给出长度为m的要询问的串. q组询问:每组询问输出 ‘1’或者‘0’ 每组询问 一对x,y 问在x到y中有没有模板串 ...
- python smtp 发邮件 添加附件
# -*- coding:utf-8 -*- # __author__ = 'justing' import os import smtplib from email.mime.multipart i ...
- Random Forest总结
一.简介 RF = Bagging + Decision Tree 随机:数据采样随机,特征选择随机 森林:多个决策树并行放在一起 几个误区: 不是每棵树随机选择特征,而是每一个结点都随机选择固定数目 ...
- ElasticSearch 随笔
1.如何用亚马逊S3存储一个ES服务索引.http://t.cn/R0fAJwK 2.ELK实战 - 利用Nginx日志分析API耗时.http://t.cn/R6sgQfU 3.Kibana中的地 ...
- Zepto源码分析之二(新旧版本zepto.Z方法的区别)
在上一节中讲到Z()方法,是在初始化函数init中直接调用zepto.Z() zepto.Z = function(dom, selector) { dom = dom || [] dom.selec ...
- Respone弹窗
Response.Write("<script>window.open('default.aspx?iID=" + GridView1.DataKeys[GridVie ...
- Xamarin.Forms + Prism,整理页面导航跳转流程
3个Page,Page1 -> Page2 -> Page3 -> Page2 -> Page1. PageViewModel实现接口:INavigatingAware, IN ...