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. 微信小程序细节

    微信小程序开发几个细节: 1.界面传值 ①全局参数传值 <!--结果--> <view wx:for="{{data}}" class="case pr ...

  2. 病毒注册表常用目标Svchost和Explorer

    Windows系统的Svchost.exe和Explorer.exe两种进程,作为Windows系统中两种重要的进程,下面我们就来看看他们的特点以及在各个操作系统中的应用. Explorer.exe ...

  3. oracle审计例子

    1.数据库开启审计alter system set audit_trail=db,extended scope=spfile;shutdown immediatestartup 2.对某个表进行审计c ...

  4. 复选框批量删除操作-jquery方式

    1.首先在页面添加一个批量删除的按钮:<li class="btns"><input id="deleteSubmit" class=&quo ...

  5. Java多线程编程作业总结

    一.多线程知识总结 1.线程同步 有关创建线程的知识就不过多的叙述了.就从主要的开始讲吧,讲一下线程的同步.与操作系统中的进程同步一样,线程同样面临着资源共享的问题,怎样处理线程的资源共享是运用多线程 ...

  6. Actions对Element的一些操作解析

    针对Chrome浏览器: 在自动化测试的编写中如果报出Element is not visible to click at xxxx point时,我会使用: new Actions(WebDrive ...

  7. vba编程基础2

    安装office2010的时候, 最好是 完全安装/完整安装 , 这样可以查阅 excel的 "帮助文档" 帮助文档中包含了更多的/更详细的 参考信息. 普通模块无事件, 只有 子 ...

  8. 0-1背包dp|波动数列|2014年蓝桥杯A组10-fishers

    标题:波动数列 观察这个数列: 1 3 0 2 -1 1 -2 ... 这个数列中后一项总是比前一项增加2或者减少3. 栋栋对这种数列很好奇,他想知道长度为 n 和为 s 而且后一项总是比前一项增加a ...

  9. L2-001:dijskstra + 多条最短路径 + 记录中间路径

    题目链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805073643683840 思路: dijkstra算出最短路 ...

  10. Nacos整合Spring Cloud Gateway实践

    Spring Cloud Gateway官网:http://spring.io/projects/spring-cloud-gateway Eureka1.0的问题和Nacos对比:https://w ...