Codeforces 458C - Elections
思路:
三分凹形函数极小值域
代码:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a)) const int N=1e5+;
const int INF=0x7f7f7f7f;
vector<int>g[N],vc;
int n;
int cost(int x){
int need=x-g[].size(),ans=;
vc.clear();
for(int i=;i<N;i++){
for(int j=;j<g[i].size();j++){
if(g[i].size()-j>=x){
need--;
ans+=g[i][j];
}
else vc.pb(g[i][j]);
}
}
sort(vc.begin(),vc.end());
for(int i=;i<need;i++)ans+=vc[i];
return ans;
}
int main(){
ios::sync_with_stdio(false);
cin.tie();
cout.tie();
int a,b;
cin>>n;
for(int i=;i<n;i++)cin>>a>>b,g[a].pb(b);
for(int i=;i<N;i++)sort(g[i].begin(),g[i].end());
int l=g[].size(),r=n,m1=(l+l+r)/,m2=(l+r+r)/;
while(l<r){
if(cost(m1)>cost(m2)){
if(l==m1)break;
else l=m1;
}
else {
if(r==m2)break;
else r=m2;
}
m1=(l+l+r)/;
m2=(l+r+r)/;
//cout<<l<<' '<<r<<' '<<m1<<' '<<m2<<endl;
}
int ans=INF;
for(int i=l;i<=r;i++)ans=min(ans,cost(i));
cout<<ans<<endl;
return ;
}
Codeforces 458C - Elections的更多相关文章
- Codeforces C. Elections(贪心枚举三分)
题目描述: C. Elections time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces Round #157 (Div. 1) B. Little Elephant and Elections 数位dp+搜索
题目链接: http://codeforces.com/problemset/problem/258/B B. Little Elephant and Elections time limit per ...
- Little Elephant and Elections CodeForces - 258B
Little Elephant and Elections CodeForces - 258B 题意:给出m,在1-m中先找出一个数x,再在剩下数中找出6个不同的数y1,...,y6,使得y1到y6中 ...
- 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 #318 [RussianCodeCup Thanks-Round] (Div. 2) A. Bear and Elections 优先队列
A. Bear and Elections ...
- CodeForces - 369C - Valera and Elections
369C - Valera and Elections 思路:dfs,对于搜索到的每个节点,看他后面有没有需要修的路,如果没有,那么这个节点就是答案. 代码: #include<bits/std ...
- CodeForces - 457C:Elections(三分)
You are running for a governor in a small city in Russia. You ran some polls and did some research, ...
- codeforces Codeforces Round #318 div2 A. Bear and Elections 【优先队列】
A. Bear and Elections time limit per test 1 second memory limit per test 256 megabytes input standar ...
- 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 ...
随机推荐
- 安装python3.7和PyCharm专业版
安装python3.7 安装PyCharm专业版 1.下载地址http://www.jetbrains.com/pycharm/download/,选择windows下面的Professional,点 ...
- oracle RAC如何正确地删除ASM磁盘组
1.登录到命令行 切换到grid用户 [grid@swnode1 ~]$ sqlplus / as sysasm SQL*Plus: Release Production on Wed May :: ...
- thiniphp tp5 使用缓存
在应用或者模块配置文件中配置好所用缓存的类型及相关参数: 如果是文件类型可以用 'cache' => [ 'type' => 'File', 'path' => CACHE_PATH ...
- vim改善生活的几个插件
vim改善生活的几个插件 http://www.cnblogs.com/lovesaber/archive/2012/01/06/2315343.html
- 比酒量|2012年蓝桥杯B组题解析第三题-fishers
(5')比酒量 有一群海盗(不多于20人),在船上比拼酒量.过程如下:打开一瓶酒,所有在场的人平分喝下,有几个人倒下了.再打开一瓶酒平分,又有倒下的,再次重复...... 直到开了第4瓶酒,坐着的已经 ...
- hihoCoder week227 Longest Subsequence
题目链接 https://hihocoder.com/contest/hiho227/problem/1 题目详解 https://hihocoder.com/discuss/question/558 ...
- .net core mvc 错误信息显示 ModelState.AddModelError
关于ModelState.AddModelError错误信息不在前端页面显示问题.经过一位高人指定终于知道了为什么,在次写着警示自己看文档一定要仔细.再次感谢这为兄弟 https://www.cnbl ...
- 嵌入式Linux要学哪些东西?你真的造吗?
嵌入式Linux要学哪些?一些人总在寻思,怕走了弯路,又怕学的东西离企业需求远.那么今天就请华清远见高级讲师曹大神告诉你,9点浅析嵌入式学习步骤.下面是他本人亲笔. 1.要学习Linux,首先要会用, ...
- 【转载】C++宏定义详解
摘自:http://blog.chinaunix.net/uid-21372424-id-119797.html C++宏定义详解 2011-02-14 23:33:24 分类: C/C++ ...
- Linux安装svn客户端
Red Hat Linux 1.安装$ yum install subversion 2.常见问题1.执行svn报错:cannot set LC_CTYPE localevi /etc/profile ...