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

代码:

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define N 200005
  4. int x[N];
  5. map<int,int>mp;
  6. int n;
  7. int main()
  8. {
  9. while(~scanf("%d",&n))
  10. {
  11. mp.clear();
  12. for(int i=;i<=n;i++)
  13. {
  14. int k;
  15. scanf("%d",&k);
  16. mp[k]++;
  17. }
  18. map<int,int>::iterator it;
  19. int tot=;
  20. for(it=mp.begin();it!=mp.end();it++)
  21. {
  22. x[tot++]=(*it).second;
  23. }
  24. sort(x,x+tot);
  25. long long ans=;
  26. for(int i=;i<=n;i++)
  27. {
  28. long long tmp=;
  29. int pos=;
  30. for(int j=i;j<=n;j*=)
  31. {
  32. int t=lower_bound(x+pos,x+tot,j)-x;
  33. if(t==tot) break;
  34. tmp+=j;
  35. pos=t+;
  36. }
  37. ans=max(ans,tmp);
  38. }
  39. printf("%lld\n",ans);
  40. }
  41.  
  42. return ;
  43. }

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. python去除字符串中间空格的方法

    1.使用字符串函数replace a = 'hello world' a.replace(' ', '') # 'helloworld' 2.使用字符串函数split a = ''.join(a.sp ...

  2. git如何上传大文件,突破大小限制

    Github中单个文件的大小限制是100MB,为了能突破这个限制,我们需要使用Git Large File Storage这个工具, git lfs install git lfs track &qu ...

  3. DispatcherServlet的工作原理

    下面是DispatcherServlet的工作原理图,图片来源于网络. 下面是我从DispatcherServlet源码层面来分析其工作流程: 1.请求到达后,调用HandlerMapping来查找对 ...

  4. Integer类的缓存机制

    一.Integer类的缓存机制 我们查看Integer的源码,就会发现里面有个静态内部类. public static Integer valueOf(int i) { assert IntegerC ...

  5. AOP技术介绍--(.Net中关于AOP的实现)

    一.AOP实现初步       AOP将软件系统分为两个部分:核心关注点和横切关注点.核心关注点更多的是业务逻辑,关注的是系统核心的业务:而横切关注点虽与核心的业务实现无关,但它却是一种更通用的业务, ...

  6. jQuery ajax上传文件实例

    jQuery ajax上传文件实例 <form id="form" enctype="multipart/form-data"><input ...

  7. git怎样删除未监视的文件untracked files ?

    git怎样删除未监视的文件untracked files 需要添加到.gitignore文件 # 删除 untracked files git clean -f # 连 untracked 的目录也一 ...

  8. 学习日记14、EF 时间段查询

    m_Rep.GetList(a => System.Data.Entity.DbFunctions.DiffDays(DateTime.Now, a.EndDate) < date); 命 ...

  9. XX-Net 使用教程(Across the Great Wall)

    注意: 由于封锁严重,软件自带IP已经被封杀殆尽.因此需要数分钟到数小时的初始化IP扫描,方能正常运行. 虽然系统内置了公共appid, 还是建议部署自己的appid,公共appid限制看视频.需要注 ...

  10. 刷leetcode之路

    写的不是很好,仅记录自己所写的,仅供参考. 第七题: Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = ...