codeforces cf 521(div3) E题
本题让我重视到对lower_bound这个函数不是特别会用。
lower_bound(int * ,int *,int )
第一个参数是数组首地址,由于c++语言的特殊性,传入第一个参数可以是数组首地址+i,表示从数组第i个元素查找(对于下标从1开始的数组)
第二个参数是数组末位+1,这里可以把数组最后一位想象成INF,从头开始,如果发现哪一位大于等于要查找的数字就返回哪一位的地址。
第三个参数是要查找的数字。
然后这道题把所有数字离散化存入一个桶里从小到大排序
然后从第一位到最后一位暴力枚举
1每次都要枚举每一个小于等于这一位上的数字,
2对于枚举的每个数字,每次用lower_bound查找这一位数字后面的所有数字里面第一个大于等于这个数字的数。
3然后把数字乘二,位置移到查找到的位置,
直到位置超出数组总数后更新答案。
#include<bits/stdc++.h>
using namespace std;
int a[200010];
int aa[200010];
int b[200010];
int cnt[200010];
int tot;
int main()
{int n;scanf("%d",&n);for(int i=1;i<=n;i++)scanf("%d",&a[i]);//将a[i]离散化sort(a+1,a+n+1);aa[++tot]=a[1];for(int i=2;i<=n;i++){if(a[i]!=a[i-1]){aa[++tot]=a[i]; //去重,tot是数组中有几个不同的数字 }}for(int i=1;i<=n;i++){b[i]=lower_bound(aa+1,aa+tot+1,a[i])-aa;//lower_bound只对有序数组有效 }//b[i]里面存了离散化数组//统计b[i]中有多少每个数字出现的个数 for(int i=1;i<=n;i++){cnt[b[i]]++;//cnt有tot个数字 }sort(cnt+1,cnt+tot+1);int res=0;for(int i=1;i<=tot;i++){int pos=i;for(int num=1;num<=cnt[pos];num++){int now=0;int tmp=pos;int num1=num;while(tmp<=tot){now+=num1;tmp=lower_bound(cnt+tmp+1,cnt+tot+1,num1*2)-cnt;num1*=2;}res=max(res,now);}}printf("%d\n",res);
}
转载于:https://www.cnblogs.com/lishengkangshidatiancai/p/9978073.html
codeforces cf 521(div3) E题相关推荐
- 【Codeforces】A3组刷题记录( 43 / 43 )
目录 A1. Combination Lock A2. Summer Camp rzt A3. Soft Drinking ★A4. Coder ★A5. GukiZ and Contest ★A6. ...
- CF 有趣的规律题总结
CF 有趣的规律题总结 1 CF 280C Game on tree 2 CFdiv2 D&&div1 B Chemical table CF 有趣的规律题总结 1 CF 280C G ...
- codeforces round 421 div2 补题 CF 820 A-E
A Mister B and Book Reading O(n)暴力即可 #include<bits/stdc++.h> using namespace std; typedef lon ...
- codeforces round 418 div2 补题 CF 814 A-E
A An abandoned sentiment from past 水题 #include<bits/stdc++.h>using namespace std;int a[300],b[ ...
- codeforces round 422 div2 补题 CF 822 A-F
A I'm bored with life 水题 #include<bits/stdc++.h> using namespace std; typedef long long int LL ...
- codeforces round 420 div2 补题 CF 821 A-E
A Okabe and Future Gadget Laboratory 暴力 #include<bits/stdc++.h> using namespace std; typedef l ...
- Codeforces 1205C Palindromic Paths (交互题、DP)
题目链接 http://codeforces.com/contest/1205/problem/C 题解 菜鸡永远做着变巨的梦 然而依然连div1BC题都不会做 要是那天去打cf怕是又要1题滚粗了.. ...
- CF Gym 100227 I题 题解
这场Gym全名是这个:2013-2014 CT S01E01: Extended 2000 ACM-ICPC East Central North America Regional Contest ( ...
- CF data structure 自制题单(一)
CF data structure 2000~2100 为你的战斗,献上雷鸣般的喝彩!--唔姆 目标 30 道题 1. Problem - 1555E - Codeforces 看了提示 给一些线段, ...
最新文章
- MySQL 5.1 分区技术初探(一)
- wifi网络结构(下)
- error while loading shared libraries:libmysqlclient.so.18 错误
- salero网店的官方邮箱设置
- Abp VNext 集成sharding-core 分表分库
- 007_Web to lead
- 【Elasticsearch】es 的配置集合
- 昨天看了华星巨幕《海神号》
- 190729每日一句
- 雷赛控制卡总线方式的坑
- JavaScript写入文件到本地
- android常用单词,Android的英语单词记忆软件系统
- IOS测试——keychain_dumper工具的使用
- 撸了个反代工具, 可用于激活JRebel
- 独家 | 全球2000家客户,这家公司推动林肯MKZ成为最流行的自动驾驶样车
- Linux ARM机器,源码安装mysql5.7.23,并且运行
- 通过 qemu 运行并调试 IoT 固件和不同架构的二进制文件
- 计算机与仪表电缆,计算机与仪表电缆
- Java AES加密工具类
- Struts1.x系列教程(1):用MyEclipse开发第一个Struts程序
热门文章
- 【问链-Eos公开课】第四课 EOS 的钱包创建、导入私钥
- linux的模块化,GoboLinux 017 发布,模块化的 Linux 发行版
- iviewui php,Vue UI框架对比:Element UI、Ant Design Vue、iView
- JZOJ 5922. 【NOIP2018模拟10.23】sequence
- JZOJ 5444. 【NOIP2017提高A组冲刺11.2】救赎
- v3是c语言吗 yolo_YOLOv3
- Ubuntu16.04安装ROS kinetic
- 边缘检测robert原理_机器视觉边缘模式检测应用
- python父类的类成员怎么定义_python如何找到哪些父类定义子对象的方法
- ssh协议是tcp还是udp_DNS 支持 TCP 和 UDP 双协议,但为何偏偏只钟情 UDP?