B 题过的有些牵强,浪费了很多时间,这种题一定想好思路和边界条件再打,争取一发过。
  D 题最开始读错题,后面最后发现可以重复感觉就没法做了,现在想来,数据量大,但是数据范围小
枚举不行,二分还是可以的,还是自己的二分水平太差了,平时周一到周四做CF,周五周末复习CF,学习
新的算法,并抽空进行专项训练

D题的思路其实很简单,我通过二分一个copy的次数val,这样我再去用每个数出现的CNT[i]/val,就是这个数

回在T序列中出现多少次,那么check直接上就行,但是要注意,我需要输出的不是val,而是序列T,那么我需要

每次跑一下,看是否满足,但是到了边界条件时,发现已经不满足了,但是这时ans数组已经改变,不过不要担心,我们只需要一直把满足条件的val维护就行。最后的时候再跑一次check函数就行。

D题代码

  1. #include<iostream>
  2. #include<stdio.h>
  3. #include<string.h>
  4. #include<algorithm>
  5. #include<math.h>
  6. #include<map>
  7. using namespace std;
  8. const int maxx = 2e5+;
  9. int a[maxx];
  10. int cnt[maxx];
  11. int n,k;
  12. int ans[maxx];
  13. int anss;
  14. bool check(int val)
  15. {
  16. int num=;
  17. int tot =;
  18. for (int i=; i<maxx; i++)
  19. {
  20. for (int j=val; j<=cnt[i]; j+=val)
  21. {
  22. num++;
  23. ans[tot++]=i;
  24. }
  25. }
  26. if (num>=k)return ;
  27. else return ;
  28. }
  29. void fen(int l,int r)
  30. {
  31. int mid=(l+r)/;
  32. if (l<=r)
  33. {
  34. if (check(mid))
  35. {
  36. anss=mid;
  37. fen(mid+,r);
  38. }
  39. else
  40. {
  41. fen(l,mid-);
  42. }
  43. }
  44. return;
  45. }
  46. int main()
  47. {
  48. scanf("%d%d",&n,&k);
  49. memset(cnt,,sizeof(cnt));
  50. for (int i=; i<=n; i++)
  51. {
  52. scanf("%d",&a[i]);
  53. }
  54. int l=;
  55. int r=0x3f3f3f3f;
  56. for (int i=; i<=n; i++)
  57. {
  58. cnt[a[i]]++;
  59. }
  60. fen(l,r);
  61. check(anss);
  62. for (int i=;i<=k; i++)
  63. {
  64. if (i!=k)printf("%d ",ans[i]);
  65. else printf("%d\n",ans[k]);
  66. }
  67. return ;
  68. }
  69. /*
  70.  
  71. */

后面留坑

E题 每天组织一场比赛,后一天的比赛题目数是前一天比赛数目的两倍,并且每天的题目必须是一样,并且第一天题目可以自己选,问最大选题的数目是多少。

这道题我最开始理解错题意了,后来然后也没有想到,最后读懂题目,发现没办法做。其实我们发现,要把次数用map统计,这并没有什么问题,然后把这些值进行离散化,也就是把每种数存下来就行。然后再用一个数组存这些数出现的次数,排序,然后用low_bound查找需要次数。最后递增就行

给出n道有类型的题目,每天组织一场专题比赛,该天题目数量必须是前一天的2倍,第一天的题目数量可以任意选择,求能消耗的最多题目数量

  1. #include<iostream>
  2. #include<string.h>
  3. #include<stdio.h>
  4. #include<algorithm>
  5. #include<map>
  6. using namespace std;
  7. int b_size;
  8. int a_size;
  9. map<int,int>p;
  10. vector<int>a,b;
  11. int check(int x)
  12. {
  13. int sum=;
  14. int pos=;
  15. while()
  16. {
  17. pos=(lower_bound(b.begin()+pos,b.end(),x)-b.begin());//大于或等于val的第一个元素位置
  18. if (pos==a_size)break;//如果都比这个数小那么返回的pos==数组大小
  19. pos++;
  20. sum+=x;
  21. x*=;
  22. }
  23. return sum;
  24. }
  25. int main()
  26. {
  27. int n;
  28. int tmp;
  29. int mx=;
  30. p.clear();
  31. scanf("%d",&n);
  32. for (int i=; i<=n; i++)
  33. {
  34. scanf("%d",&tmp);
  35. if (p[tmp]==)
  36. {
  37. a.push_back(tmp);
  38. }
  39. p[tmp]++;
  40. mx=max(mx,p[tmp]);
  41. }
  42. b_size=a_size=a.size();
  43. for(int i=; i<a_size; i++)
  44. {
  45. b.push_back(p[a[i]]);
  46. }
  47. sort(b.begin(),b.end());
  48. int ans=;
  49. for (int i=; i<=mx; i++)
  50. {
  51. ans=max(ans,check(i));
  52. }
  53. printf("%d\n",ans);
  54. return ;
  55. }

F1 简单DP,用DP[i][j]代表前i位置,选j元素的最大值。

转移方程dp[i][l+1]=max(dp[i][l+1],dp[j][l]+a[i])

表示前i个元素,选取了l+1个元素,我们需要从这个数的前i-k个元素,选取了l个元素传递过来。

代码如下:

  1. #include<iostream>
  2. #include<stdio.h>
  3. #include<string.h>
  4. #include<algorithm>
  5. #define ll long long
  6. using namespace std;
  7. ll a[];
  8. ll dp[][];
  9. const ll inf = 0x3f3f3f3f;
  10. int main()
  11. {
  12. ll n,k,x;
  13. scanf("%lld%lld%lld",&n,&k,&x);
  14. {
  15. for(int i=; i<=n; i++)
  16. {
  17. scanf("%lld",&a[i]);
  18. }
  19. memset(dp,-inf,sizeof(dp));
  20. dp[][]=;
  21. //dp[i][j]前i个选出j个
  22. for(int i=; i<=n; i++)//前i个选出l+1个
  23. {
  24. for(int j=i-; j>=max((ll),i-k); j--)//从前i-k位到i-1位,选出l个加上i位置选出a[i]
  25. {
  26. for(int l=; l<x; l++)
  27. dp[i][l+]=max(dp[i][l+],dp[j][l]+a[i]);
  28. }
  29. }
  30. ll maxn;
  31. maxn=-;
  32. for (int i=n; i>n-k; i--)
  33. {
  34. maxn=max(dp[i][x],maxn);
  35. }
  36. printf("%lld\n",maxn);
  37. }
  38. return ;
  39. }

Codeforces Round #521 (Div. 3)的更多相关文章

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

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

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

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

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

  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 玩耍记

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

  9. Codeforces Round #521 (Div. 3) C. Good Array

    C. Good Array time limit per test 1 second memory limit per test 256 megabytes input standard input ...

随机推荐

  1. aspectj eclipse4.6下载地址

    http://www.eclipse.org/ajdt/downloads/#46zips

  2. 自动化测试的Selenium的python版安装与使用

    Selenium是专做网页自动化测试的,即web drive,通过百度Selenium就能找到Selenium的官网 由图可见,selenium支持相当多的编程语言进行网页自动化测试,这里我们使用py ...

  3. 转:Log Explorer使用说明恢复被误删除的数据

    一.介绍 Log Explorer主要用于对MSSQLServer的事物分析和数据恢复.你可以浏览日志.导出数据.恢复被修改或者删除的数据(包括执行过update,delete,drop和trunca ...

  4. c/c++ 重载new,delete运算符 placement new

    重载new,delete运算符 new,delete在c++中也被归为运算符,所以可以重载它们. new的行为: 先开辟内存空间 再调用类的构造函数 开辟内存空间的部分,可以被重载. delete的行 ...

  5. App分享之微信微博等各个社交平台的分享授权规则和常见问题

    一.新浪微博分享规则 新浪微博支持分享类型: 应用内分享也就是网页分享支持: 文字,文字+图片,要分享链接需要链接添加在text里分享 客户端分享支持:文字,图片,文字+图片,图片+文字+链接 参数说 ...

  6. iOS application/json上传文件等

    在和sever后台交互的过程中.有时候.他们需要我们iOS开发者以“application/json”形式上传. NSString *accessUrl = [NSString stringWithF ...

  7. Entity Framework 5.0.0 Function Import 以及 ODP. NET Implicit REF CURSOR Binding使用简介

    源代码 概要: 1,说明如何使用Entity Framework中的function import功能. 2,说明如何使用ODP.NET的隐式REF CURSOR绑定(implicit REF CUR ...

  8. 4.8Python数据处理篇之Matplotlib系列(八)---Figure的学习

    目录 目录 前言 (一)figure()方法的定义 (二)figure()方法的参数 (三)figure()方法的例子 1.多窗体绘图: 2.窗口得分别率 目录 前言 今天我们来学习一下plt.fig ...

  9. JavaScript原型链和继承

    1.概念 JavaScript并不提供一个class的实现,在ES6中提供class关键字,但是这个只是一个语法糖,JavaScript仍然是基于原型的.JavaScript只有一种结构:对象.每个对 ...

  10. Word中的通配符随意组合进行批量替换或删除某些内容

    长文档需要批量修改或删除某些内容的时候,我们可以利用Word中的通配符来搞定这一切,当然,前提是你必须会使用它.通配符的功能非常强大,能够随意组合替换或删除我们定义的规则内容,下面易老师就分享一些关于 ...