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

题目传送门

题意:

现在有n个题目,每种题目有自己的类型
要举办一次考试,
考试的原则是
每天只有一种题目类型
一种题目类型只能出现在一天
每天的题目类型不能相同,
而且后一天的题目数量必须正好为前一天的两倍,第一天的题目数量是任意的
求怎么安排能使题目尽量多。注意:不是天数尽量多

思路:

首先我们知道一件事,题目属于哪种类型并不重要,重要的是每种类型的个数
所以我们先统计出所有类型的个数,存进一个数组,
而最终最优解一定是按照题目数量从小到大来的,所以我们对该数组进行排序
而我们怎么确定最终怎么选择呢,我们发现最终怎么选择取决于第一天怎么选择
而且只要确定了第一天的题目数。我们要看哪个过程可以优化
第一天的题目数并不满足二分的性质,我们就考虑优化能选就选这个原则
在排好序的数组上我们可以通过lower_bound快速找到>=当前所需数目的下标pos
之后让pos++,继续下一次查找,这样我们最多查找log次就能完成check
于是这道题就是O(n) O(n)O(n)枚举第一天的题目数,O(logn) O(logn)O(logn)check,总复杂度O(nlogn) O(nlogn)O(nlogn)

原文来自:https://blog.csdn.net/qq_38891827/article/details/84149250

代码:

#include<bits/stdc++.h>
using namespace std;
#define N 200005
int x[N];
map<int,int>mp;
int n;
int main()
{
while(~scanf("%d",&n))
{
mp.clear();
for(int i=;i<=n;i++)
{
int k;
scanf("%d",&k);
mp[k]++;
}
map<int,int>::iterator it;
int tot=;
for(it=mp.begin();it!=mp.end();it++)
{
x[tot++]=(*it).second;
}
sort(x,x+tot);
long long ans=;
for(int i=;i<=n;i++)
{
long long tmp=;
int pos=;
for(int j=i;j<=n;j*=)
{
int t=lower_bound(x+pos,x+tot,j)-x;
if(t==tot) break;
tmp+=j;
pos=t+;
}
ans=max(ans,tmp);
}
printf("%lld\n",ans);
} return ;
}

Codeforces Round #521 (Div. 3) E. Thematic Contests(思维)的更多相关文章

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

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

  2. Codeforces Round #521 (Div. 3) E. Thematic Contests (离散化,二分)

    题意:有\(n\)个话题,每次都必须选取不同的话题,且话题数必须是上次的两倍,第一次的话题数可以任意,问最多能选取多少话题数. 题解:我们首先用桶来记录不同话题的数量,因为只要求话题的数量,与话题是多 ...

  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 #521 (Div.3) D. Cutting Out

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

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

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

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

  8. Codeforces Round #521 (Div. 3)

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

  9. Codeforces Round #521 Div. 3 玩耍记

    A:签到. #include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> ...

随机推荐

  1. Linux就该这么学04学习笔记

    今天开始学习,开始做笔记,希望自己能坚持下去 参考链接:https://www.linuxprobe.com/chapter-04.html vim编辑器 Linux系统中通用的文本编辑器 vi的升级 ...

  2. Linux性能优化从入门到实战:11 内存篇:内存泄漏的发现与定位

      用户空间内存包括多个不同的内存段,比如只读段.数据段.堆.栈以及文件映射段等.但会发生内存泄漏的内存段,只有堆和文件映射段中的共享内存.   内存泄漏的危害非常大,这些忘记释放的内存,不仅应用程序 ...

  3. linux下的mongodb的备份与恢复

    mongodb的备份有两种方式: 1.直接拷贝数据目录下的一切文件 2.使用mongodump方式 3.主从复制:http://www.cnblogs.com/huangxincheng/archiv ...

  4. 01scikit-learn数据集下载

    In [2]: from sklearn.datasets import load_iris iris = load_iris() iris.keys() Out[2]: dict_keys(['da ...

  5. man uname

    UNAME(1)         User Commands/用户命令        UNAME(1) NAME/名称       uname - print system information/打 ...

  6. MySQL WAL

    原创转载请注明出处:https://www.cnblogs.com/agilestyle/p/11447794.html WAL: Write-Ahead Logging 先写日志,再写磁盘.具体说, ...

  7. SpringBoot之Web进阶

    .. 另外包括Springboot常用技术整合  以及项目上的应用

  8. Eclipse 4.9 创建springboot项目步骤

    上一篇文章写了eclipse安装STS. 现在创建Spring Starter Project  具体步骤如下: 1.等你安装好STS后,就在Eclipse >  File >New 选择 ...

  9. linux运维、架构之路-MySQL主从复制

    一.MySQL主从复制原理图  MySQL主从复制原理:实现主从复制原理是三个线程完成的,主的I/O线程,备的I/O线程与SQL线程 1.首先主库db01需要开启binlog.授权一个replicat ...

  10. visual studio 编译报错:未能向文件“....csproj.FileListAbsolute.txt”写入命令行,对路径的访问被拒绝

    在网上开始查找出错的解决方法,终于找到了,原来解决方法这么简单,当初以为是权限的问题,后来发现不是权限问题,在VSS中比以前多了两个目录“bin”和“obj”,可能是有人上传的时候将这两个文件夹一起上 ...