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相关推荐

  1. Codeforces Problem-1593A Elections

    Codeforces Problem-1593A Elections 题目链接 基本思想: 题目比较简单,直接暴力枚举即可. AC代码: #include <bits/stdc++.h> ...

  2. codeforces 369C Valera and Elections

    为什么80%的码农都做不了架构师?>>>    codeforces 369C Valera and Elections ###题目描述 n个节点和n - 1条双向边组成了一棵树.这 ...

  3. 【CodeForces - 1020C】Elections (枚举投票数,贪心)

    题干: As you know, majority of students and teachers of Summer Informatics School live in Berland for ...

  4. *【CodeForces - 574A】Bear and Elections (优先队列,水题模拟)

    题干: Limak is a grizzly bear who desires power and adoration. He wants to win in upcoming elections a ...

  5. 【CodeForces - 570A】Elections(模拟,水题)

    题干: The country of Byalechinsk is running elections involving n candidates. The country consists of  ...

  6. CodeForces 258B Little Elephant and Elections 数位DP

    前面先用数位DP预处理,然后暴力计算组合方式即可. #include <cstdio> #include <cstring> #include <cmath> #i ...

  7. Codeforces 258B Little Elephant and Elections

    题意:有7个人从m个数中任选一个不重复的,其中4和7是幸运数,一个人的幸运值等于他所选的数字中所有'4'的个数+'7'的个数.求一个人的幸运值比其他6人幸运值总和大的方案数. 1 #include & ...

  8. Codeforces Round #503 (by SIS, Div. 2) C. Elections

    气死我了人生中第一次打cf就掉分了 A题大水题浪费太多时间囧明明都是A两题亮老师还上分了.. 表示C题打的时候就想到正解啊(而且还更加优秀,因为家里老爷机暴力跑的超龟以为不行 其实是没认真算复杂度), ...

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

最新文章

  1. ASP.NE的缓存技术提高Web站点的性能
  2. 无招胜有招之Java进阶JVM(一)
  3. 第一个Android工程HelloAndroid
  4. 为什么要远程连接Linux
  5. PS如何做文字扫描效果(用于较淡的扫描件)
  6. [SourceTree - Git] 如何解决冲突 (以我的版本解决冲突以他人版本解决冲突)
  7. 计算机组成原理实验箱教程,计算机组成原理实验箱的技术参数和性能指标
  8. Android 听筒模式和扬声器模式切换的 实现
  9. Funcode-Q版泡泡堂
  10. 【信号与系统学习笔记 3】—— 系统,以及系统的性质以及判断方法解析
  11. 公司酒场被劝“你不喝就不拿我当朋友”,用4种拒酒话术,特管用
  12. 安装Bumblebee解决Ubuntu笔记本发热量大问题
  13. 计算机桌面怎么全屏显示,电脑显示器如何设置全屏 把电脑屏幕调成满屏的方法有哪些...
  14. PTA乙级-1061 判断题-C语言版
  15. 微信小程序开发大赛经验总结
  16. 电子信息科学与技术与计算机专业相近吗,电子信息科学与技术专业简介
  17. 从《江南百景图》厨艺大赛说起,聊聊博弈和“奶油系统”
  18. QML一个漂亮的仪表盘
  19. 一个完整的量化模型包括哪些
  20. 台北淡水 渔人码头之行 1

热门文章

  1. UPnP协议编程实践
  2. .net平台下C#socket通信(中)
  3. 使用Entity Framework code first, migration
  4. 模块的使用,包,及程序开发规范
  5. Hadoop- MapReduce分布式计算框架原理
  6. spring 获取 WebApplicationContext的几种方法
  7. data类型的Url格式及Base64编码:把小数据直接嵌入到Url中
  8. 用Apache Hadoop和Apache Solr处理和索引医学图像
  9. 最大似然估计的一个示例
  10. Google Protocol Buffer 的使用和原理