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 ...
随机推荐
- 使用v-bind处理class与style
普通的css引入: 变量引入: 通过定义一个变量fontColor来通过v-bind来进行绑定在h3z的class中 <!--变量引入--> <h3 :class="fon ...
- oracle 12cR1&12cR2核心高实用性新特性
今天把本地环境升到了12.2.12c应该来说无论从性能和功能性方面都得到了很大的加强,就是不知道实际license怎么卖...原来有些功能在exadata中可用的,现在在12c中可用了,估计很大程度上 ...
- 04: nginx部署vue
1.1 基本配置 server { listen 9000; server_name 1.1.1.3; #access_log logs/access_example.log main; root / ...
- 深度学习demo
1. Stanford Convolutional Neural Network on the MNIST digits dataset http://cs.stanford.edu/people/k ...
- Redhat普通用户如何使用管理员权限
作为一个普通用户, 很多地方收到权限的控制, 下面展示sudoers大法, 主要就是sudo的问题了. 下面的是我的普通用户lee 还没有授权之前是这样的 开始授权 切换到root用户, 修改sudo ...
- bzoj 1095 Hide 捉迷藏 - 动态点分治 -堆
Description 捉迷藏 Jiajia和Wind是一对恩爱的夫妻,并且他们有很多孩子.某天,Jiajia.Wind和孩子们决定在家里玩捉迷藏游戏.他们的家很大且构造很奇特,由N个屋子和N-1条双 ...
- bzoj 1014 火星人prefix - 链表 - 分块
Description 火星人最近研究了一种操作:求一个字串两个后缀的公共前缀.比方说,有这样一个字符串:madamimadam,我们将这个字符串的各个字符予以标号:序号: 1 2 3 4 5 6 7 ...
- 学习Struts2的个人疑惑及问题解决
刚开始学习SSH框架中Struts2时,个人疑惑以及一些问题总结一下. 1.package节点namespace属性值决定访问路径问题 namespace不写或写namespace=&qu ...
- tp框架中的一些疑点知识-8
NaN是Number对象的一个属性, 表示一个特殊值, 表示不是一个 数字, 引用/赋值时, 要使用: Number.NaN 判断 一个值是不是 NaN, 用 isNaN() 函数, 它是一个js的全 ...
- Newcoder Metropolis(多源最短路 + Dijkstra堆优化)题解
题目链接:https://www.nowcoder.com/acm/contest/203/I?tdsourcetag=s_pcqq_aiomsg来源:牛客网 思路:我们用用fa[i]表示距离i最近的 ...