Codeforces Round #521 (Div. 3) E - Thematic Contests (二分 + STL)
题目链接:http://codeforces.com/contest/1077/problem/E
题意:首先给你一个长度为n的序列,表示一共有n个问题。其中某些问题属于同一种话题。现在要让你举办一天接一天的比赛,每天比赛要选择这些话题中的选择一个话题来进行解决问题。每天的比赛有如下要求:
第一 :当天话题对应的问题的个数应该是前天的两倍。如:前一天我们讨论的是话题3,问题个数为2的话,当天我们就得选择一个问题个数为4的话题。
第二:我们要求总共解决问题的个数最大。而不是举办比赛的次数最大。
第三:第一天我们可以选择任意数量的问题。
题解:我们可以知道第一天的选择问题的个数,直接导致了后面选择话题。我们可以暴力枚举第一天选择了几个问题。然后只需要从按照问题数量从小到大的排好序的话题中依次挑选合适的即可。
我们用二分的方法来判断当天需要问题个数的位置。
所以解决问题过程如下:
第一:对话题按照问题数量排序。
第二:枚举第一天选择了多少问题
第三:计算第一天问题选择的个数 i 能总共选出多少问题。
第四:求最大值。
注意:
第一:这个不能用桶排序的方法记录每个话题的数量。因为话题的大小为1e9。所以我们用map来存。然后再把结果放回数组中。
第二:当我们选择问题的数量大于2e5时,可以直接跳出选择话题的过程。
代码如下:
#include<bits/stdc++.h>
using namespace std;const int maxn = 2e5 + 10;
struct node{int key;int val;bool operator < (const node &a) const{return val > a.val;}
};
map<int,int> mp;
priority_queue<node> q;
int num[maxn];
int cnt ;int slove(int x){int count = x;int flag = 1;int pos = 0;int sum = 0;while(flag){int s = lower_bound(num+pos,num+cnt,count) - num;if(s < cnt){pos = s + 1;sum += count;count <<= 1;}else flag = 0;if(count > maxn) flag = 0;}return sum ;}
int main(){int n;scanf("%d",&n);for(int i = 0 ; i < n ; i ++){int tmp;scanf("%d",&tmp);mp[tmp] ++;}map<int,int>::iterator it;for(it = mp.begin() ; it != mp.end() ; it ++){node now;now.key = it->first;now.val = it->second;q.push(now);//cout <<it->first << " " << it->second << endl;}cnt = 0;while(!q.empty()){node now = q.top();num[cnt ++] = now.val;q.pop();}int ans = -1;for(int i = 0 ; i < maxn ; i ++){// cout << ans << endl;ans = max(ans,slove(i));}cout << ans << endl;
}
Codeforces Round #521 (Div. 3) E - Thematic Contests (二分 + STL)相关推荐
- Codeforces Round #725 (Div. 3) G. Gift Set 二分
传送门 文章目录 题意: 思路: 题意: 有两种物品分别有x,yx,yx,y个,每次可以从一个拿出aaa个,另一个拿出bbb个分成一组,问最多能分成多少组. 思路: 这个题有一个显然的单调性,所以二分 ...
- Codeforces Round #521 (Div. 3)
题目链接:http://codeforces.com/contest/1077 A.Frog Jumping 解题思路:作差再判断最后是否还要向右跳一次即可. AC代码: 1 #include< ...
- B. Disturbed People(模拟) Codeforces Round #521 (Div. 3)
原题链接: https://codeforces.com/contest/1077/problem/B 样例: Examples Input 10 1 1 0 1 1 0 1 0 1 0 Output ...
- Codeforces Round #521 (Div. 3) B - Disturbed People (贪心)
题目链接:http://codeforces.com/contest/1077/problem/B 题意:给你一长度为n的01序列.0表示当前位置的房子灯是灭的,1表示当前房子的位置灯是亮的.判断某个 ...
- CodeForces Round #521 (Div.3) B. Disturbed People
http://codeforces.com/contest/1077/problem/B There is a house with nn flats situated on the main str ...
- Codeforces Round #521 (Div.3)题解
A过水,不讲 题解 CF1077B [Disturbed People] 这题就是个显而易见的贪心可是我考场上差点没想出来 显然把一户被打扰的人家的右边人家的灯关掉肯定比把左边的灯关掉 从左到右扫一遍 ...
- Codeforces Round #521 (Div. 3): F. Pictures with Kittens(DP+单调队列)
题意: 你有n幅画,第i幅画的好看程度为ai,再给你两个数字k,x,表示你要从中选出刚好x幅画,并且相邻两幅画的距离不能≥k,好看程度之和最大能多少,选不出来输出-1,F1数据范围<200,F2 ...
- Codeforces Round #521 (Div. 3) B. Disturbed People
There is a house with nn flats situated on the main street of Berlatov. Vova is watching this house ...
- Codeforces Round #521 (Div. 3) B. Disturbed People 思维
题解 题目大意 n个灯0关灯1开灯 101则中间的睡不着 问最少关掉多少个灯可以全都能睡着 遇见101则将后面的1的灯泡关掉 这样解决10101的问题 计数输出即可 AC代码 #include < ...
- Codeforces Round #321 (Div. 2) Kefa and Company 二分
原题链接:http://codeforces.com/contest/580/problem/B 题意: 给你一个集合,集合中的每个元素有两个属性,$m_i,s_i$,让你求个子集合,使得集合中的最大 ...
最新文章
- 徐博 From RankNet to LambdaRank to LambdaMART: An Overview
- 笔记整理-知识产权与标准化知识-GB/T11457-2006软件工程术语
- linux c mysql教程_linux下c操作mysql之增删改查
- python自动客服排班_使用或工具的护士排班问题,在某些日子增加不同的轮班时间...
- 【华为大咖分享】7.大型云平台的DevOps实践(后附PPT下载地址)
- Oracle树查询(查询所有子节点,父节点等等)_转载
- 13.地区设置(Locale Settings)
- Redis的安装和使用之二------phpredis与phpRedisAdmin
- 计算机连入局域网需要配置,设置局域网
- 计算机顶会英文论文查找
- Java加上Xtend,满足你对C#语法的所有想象
- 003-photoshop快速去掉图片背景颜色、签名放到指定文档合成图片
- (六)Linux环境部署(Centos+Nginx+Tomcat+Mysql) - 常用命令总结
- APQP , PPQP, ESO之间关系
- 实习 | 深圳市彼岸心智科技有限公司招募新成员啦
- 那些年啊 那些事——一个程序员的奋斗史 ——105
- 去除噪声 matlab 论文,基于MATLAB的语音去噪开题报告
- 实战TSA与HADR
- Alpine安装telnet
- Mac 10.12安装截图工具Jietu