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的更多相关文章

  1. Codeforces C. Elections(贪心枚举三分)

    题目描述: C. Elections time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

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

  3. Little Elephant and Elections CodeForces - 258B

    Little Elephant and Elections CodeForces - 258B 题意:给出m,在1-m中先找出一个数x,再在剩下数中找出6个不同的数y1,...,y6,使得y1到y6中 ...

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

  5. Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2) A. Bear and Elections 优先队列

                                                    A. Bear and Elections                               ...

  6. CodeForces - 369C - Valera and Elections

    369C - Valera and Elections 思路:dfs,对于搜索到的每个节点,看他后面有没有需要修的路,如果没有,那么这个节点就是答案. 代码: #include<bits/std ...

  7. CodeForces - 457C:Elections(三分)

    You are running for a governor in a small city in Russia. You ran some polls and did some research, ...

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

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

随机推荐

  1. 点击button后刷新了页面

    今天遇到一个特别奇怪的事,在页面中使用button标签,添加了点击事件onclic,点击的时候倒是执行了绑定的方法,但页面被刷新了! 什么鬼?我没与提交表单啊! 原来,button默认具有提交表单的动 ...

  2. netty集成ssl完整参考指南(含完整源码)

    虽然我们在内部rpc通信中使用的是基于认证和报文头加密的方式实现安全性,但是有些时候仍然需要使用SSL加密,可能是因为对接的三方系统需要,也可能是由于open的考虑.中午特地测了下netty下集成ss ...

  3. Getting started with Kaggle -- Kaggle Competitions

    1: The Competition We'll be learning how to generate a submission for a Kaggle competition. Kaggle i ...

  4. opencv学习之路(2)、读取视频,读取摄像头

    一.介绍 视频读取本质上就是读取图像,因为视频是由一帧一帧图像组成的.1秒24帧基本就能流畅的读取视频了. ①读取视频有两种方法: A. VideoCapture cap; cap.open(“1.a ...

  5. Codeforces Round #427 (Div. 2) Problem D Palindromic characteristics (Codeforces 835D) - 记忆化搜索

    Palindromic characteristics of string s with length |s| is a sequence of |s| integers, where k-th nu ...

  6. 2018年11月10日 input,print,pass 用法,条件语句+字符串

    name=input('请输入用户名')#永远等待用户输入 password=input('请输入密码') print(name) print(password) 变量定义的规则: 变量名只能是 字母 ...

  7. Delphi XE5 for Android (八)

    delphi xe5 编译的程序在启动时会有短暂的黑屏出现,这个现象产生是因为启动首个activity时会加载一些初始化数据,整个时间大约在2~3秒,如何处理? 网上有些资料,这里主要参考和整理了CS ...

  8. Python3 tkinter基础 Label compound 图片上显示文字 fg字体颜色 font字体大小

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  9. ssm项目部署到服务器过程

    ssm项目部署到服务器过程 特别篇 由于准备春招,所以希望各位看客方便的话,能去github上面帮我Star一下项目 https://github.com/Draymonders/Campus-Sho ...

  10. 使用python+ffmpeg+youtube-dl下载youtube上的视频

    一.准备工作 1.安装python,详见https://www.cnblogs.com/cnwuchao/p/10562416.html 2.安装ffmpeg,详见https://www.cnblog ...