• 题意:有\(n\)个话题,每次都必须选取不同的话题,且话题数必须是上次的两倍,第一次的话题数可以任意,问最多能选取多少话题数.

  • 题解:我们首先用桶来记录不同话题的数量,因为只要求话题的数量,与话题是多少无关,所以我们可以开个新数组然后离散化一下,比如\(mp[5]=6\)可以离散化成\(disc[1]=6\),\(mp[7]=2\)可以离散化成\(disc[2]=2\),这样可以方便我们进行二分查找,然后我们对\(disc\)数组sort一下,从\([1,n]\)开始进行二分,每次去找\(pos\)之后是否第一个大于等于\(now\)的位置,如果没有就break,每次二分都维护一下答案的最大值即可.

  • 代码:

    int n;
    int x;
    map<int,int> mp;
    int disc[N];
    int cnt;
    int res; int main() {
    //ios::sync_with_stdio(false);cin.tie(0);
    scanf("%d",&n);
    for(int i=1;i<=n;++i){
    scanf("%d",&x);
    mp[x]++;
    } for(auto w:mp){
    disc[++cnt]=w.se;
    }
    sort(disc+1,disc+1+cnt);
    for(int i=1;i<=n;++i){
    int sum=0;
    int pos=1;
    int now=i;
    while(true){
    int tmp=lower_bound(disc+pos,disc+1+cnt,now)-disc;
    if(disc[tmp]==0) break;
    sum+=now;
    now*=2;
    pos=tmp+1;
    }
    res=max(res,sum);
    } printf("%d\n",res); return 0;
    }

Codeforces Round #521 (Div. 3) E. Thematic Contests (离散化,二分)的更多相关文章

  1. Codeforces Round #521 (Div. 3) E. Thematic Contests(思维)

    Codeforces Round #521 (Div. 3)  E. Thematic Contests 题目传送门 题意: 现在有n个题目,每种题目有自己的类型要举办一次考试,考试的原则是每天只有一 ...

  2. CodeForces Round #521 (Div.3) E. Thematic Contests

    http://codeforces.com/contest/1077/problem/E output standard output Polycarp has prepared nn competi ...

  3. Codeforces Round #521 (Div. 3) D. Cutting Out 【二分+排序】

    任意门:http://codeforces.com/contest/1077/problem/D D. Cutting Out time limit per test 3 seconds memory ...

  4. Codeforces Round #365 (Div. 2) C - Chris and Road 二分找切点

    // Codeforces Round #365 (Div. 2) // C - Chris and Road 二分找切点 // 题意:给你一个凸边行,凸边行有个初始的速度往左走,人有最大速度,可以停 ...

  5. CodeForces Round #521 (Div.3) D. Cutting Out

    http://codeforces.com/contest/1077/problem/D You are given an array ss consisting of nn integers. Yo ...

  6. Codeforces Round #521 (Div. 3) F1. Pictures with Kittens (easy version)

    F1. Pictures with Kittens (easy version) 题目链接:https://codeforces.com/contest/1077/problem/F1 题意: 给出n ...

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

  8. CodeForces Round #521 (Div.3) A. Frog Jumping

    http://codeforces.com/contest/1077/problem/A A frog is currently at the point 00 on a coordinate axi ...

  9. Codeforces Round #521 (Div. 3)

    B 题过的有些牵强,浪费了很多时间,这种题一定想好思路和边界条件再打,争取一发过.  D 题最开始读错题,后面最后发现可以重复感觉就没法做了,现在想来,数据量大,但是数据范围小枚举不行,二分还是可以的 ...

随机推荐

  1. Spring源码深度解析之事务

    Spring源码深度解析之事务 目录 一.JDBC方式下的事务使用示例 (1)创建数据表结构 (2)创建对应数据表的PO (3)创建表和实体之间的映射 (4)创建数据操作接口 (5)创建数据操作接口实 ...

  2. python面向对象基础-属性/方法

  3. python函数2-函数参数

    rgb法则:

  4. 【Docker】在Linux系统中安装Docker虚拟机、启动停止重启查看Docker命令

    安装Docker 文章目录 安装Docker Docker虚拟机架构 在Linux系统中安装Docker虚拟机 管理Docker虚拟机 参考资料 Docker虚拟机架构 Docker创建的所有虚拟实例 ...

  5. awk -v参数

    -v var=val --assign var=val Assign the value val to the variable var, before execution of the progra ...

  6. leetcode 730. 统计不同回文子序列(区间dp,字符串)

    题目链接 https://leetcode-cn.com/problems/count-different-palindromic-subsequences/ 题意 给定一个字符串,判断这个字符串中所 ...

  7. mysql—if函数

    在mysql中if()函数的具体语法如下:IF(expr1,expr2,expr3),如果expr1的值为true,则返回expr2的值,如果expr1的值为false,则返回expr3的值. 开始实 ...

  8. Jquery实现对Array数组实现类似Linq的Lambda表达式的Where方法筛选

    平时使用Linq,习惯了Lambda表达式,用着非常顺手,奈何在Jquery里面不能这样用,只能循环一个个判断.趁空闲时间找了找,自己写了这样的扩展方法.目前写出了三种方案,没有比较性能,觉得都可以用 ...

  9. 超详细 安装VMware Workstation,并安装WIN10操作系统连接外网 步骤指导

    首先下载VMware Workstation15.1版本,我保存在迅雷链接里面,下载速度非常可观. 链接:https://pan.xunlei.com/s/VMRSt6hHMZXEmPZCm6gJcG ...

  10. HTTP协议相关知识整理:

    http协议简介 超文本传输协议:是一种用于分布式.协作式和超媒体信息系统的应用层协议. 一次请求一次响应之后断开连接(无状态,短连接) 分析http请求信息格式 http工作原理 以下是 HTTP ...