Codeforces 458C - Elections
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+5; const int INF=0x7f7f7f7f; vector<int>g[N],vc; int n; int cost(int x){int need=x-g[0].size(),ans=0;vc.clear();for(int i=1;i<N;i++){for(int j=0;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=0;i<need;i++)ans+=vc[i];return ans; } int main(){ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);int a,b;cin>>n;for(int i=0;i<n;i++)cin>>a>>b,g[a].pb(b);for(int i=0;i<N;i++)sort(g[i].begin(),g[i].end());int l=g[0].size(),r=n,m1=(l+l+r)/3,m2=(l+r+r)/3;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)/3;m2=(l+r+r)/3;//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 0; }
转载于:https://www.cnblogs.com/widsom/p/8485663.html
Codeforces 458C - Elections相关推荐
- Codeforces Problem-1593A Elections
Codeforces Problem-1593A Elections 题目链接 基本思想: 题目比较简单,直接暴力枚举即可. AC代码: #include <bits/stdc++.h> ...
- codeforces 369C Valera and Elections
为什么80%的码农都做不了架构师?>>> codeforces 369C Valera and Elections ###题目描述 n个节点和n - 1条双向边组成了一棵树.这 ...
- 【CodeForces - 1020C】Elections (枚举投票数,贪心)
题干: As you know, majority of students and teachers of Summer Informatics School live in Berland for ...
- *【CodeForces - 574A】Bear and Elections (优先队列,水题模拟)
题干: Limak is a grizzly bear who desires power and adoration. He wants to win in upcoming elections a ...
- 【CodeForces - 570A】Elections(模拟,水题)
题干: The country of Byalechinsk is running elections involving n candidates. The country consists of ...
- CodeForces 258B Little Elephant and Elections 数位DP
前面先用数位DP预处理,然后暴力计算组合方式即可. #include <cstdio> #include <cstring> #include <cmath> #i ...
- Codeforces 258B Little Elephant and Elections
题意:有7个人从m个数中任选一个不重复的,其中4和7是幸运数,一个人的幸运值等于他所选的数字中所有'4'的个数+'7'的个数.求一个人的幸运值比其他6人幸运值总和大的方案数. 1 #include & ...
- Codeforces Round #503 (by SIS, Div. 2) C. Elections
气死我了人生中第一次打cf就掉分了 A题大水题浪费太多时间囧明明都是A两题亮老师还上分了.. 表示C题打的时候就想到正解啊(而且还更加优秀,因为家里老爷机暴力跑的超龟以为不行 其实是没认真算复杂度), ...
- Codeforces Round #744 (Div. 3)【A-D E的题解】
目录 A. Elections[800 / 模拟] B. Make it Divisible by 25[900 / 思维] C. Save More Mice[1000 / 贪心] D1. All ...
最新文章
- ASP.NE的缓存技术提高Web站点的性能
- 无招胜有招之Java进阶JVM(一)
- 第一个Android工程HelloAndroid
- 为什么要远程连接Linux
- PS如何做文字扫描效果(用于较淡的扫描件)
- [SourceTree - Git] 如何解决冲突 (以我的版本解决冲突以他人版本解决冲突)
- 计算机组成原理实验箱教程,计算机组成原理实验箱的技术参数和性能指标
- Android 听筒模式和扬声器模式切换的 实现
- Funcode-Q版泡泡堂
- 【信号与系统学习笔记 3】—— 系统,以及系统的性质以及判断方法解析
- 公司酒场被劝“你不喝就不拿我当朋友”,用4种拒酒话术,特管用
- 安装Bumblebee解决Ubuntu笔记本发热量大问题
- 计算机桌面怎么全屏显示,电脑显示器如何设置全屏 把电脑屏幕调成满屏的方法有哪些...
- PTA乙级-1061 判断题-C语言版
- 微信小程序开发大赛经验总结
- 电子信息科学与技术与计算机专业相近吗,电子信息科学与技术专业简介
- 从《江南百景图》厨艺大赛说起,聊聊博弈和“奶油系统”
- QML一个漂亮的仪表盘
- 一个完整的量化模型包括哪些
- 台北淡水 渔人码头之行 1