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

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

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

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

D题代码

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<map>
using namespace std;
const int maxx = 2e5+;
int a[maxx];
int cnt[maxx];
int n,k;
int ans[maxx];
int anss;
bool check(int val)
{
int num=;
int tot =;
for (int i=; i<maxx; i++)
{
for (int j=val; j<=cnt[i]; j+=val)
{
num++;
ans[tot++]=i;
}
}
if (num>=k)return ;
else return ;
}
void fen(int l,int r)
{
int mid=(l+r)/;
if (l<=r)
{
if (check(mid))
{
anss=mid;
fen(mid+,r);
}
else
{
fen(l,mid-);
}
}
return;
}
int main()
{
scanf("%d%d",&n,&k);
memset(cnt,,sizeof(cnt));
for (int i=; i<=n; i++)
{
scanf("%d",&a[i]);
}
int l=;
int r=0x3f3f3f3f;
for (int i=; i<=n; i++)
{
cnt[a[i]]++;
}
fen(l,r);
check(anss);
for (int i=;i<=k; i++)
{
if (i!=k)printf("%d ",ans[i]);
else printf("%d\n",ans[k]);
}
return ;
}
/* */

后面留坑

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

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

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

 #include<iostream>
#include<string.h>
#include<stdio.h>
#include<algorithm>
#include<map>
using namespace std;
int b_size;
int a_size;
map<int,int>p;
vector<int>a,b;
int check(int x)
{
int sum=;
int pos=;
while()
{
pos=(lower_bound(b.begin()+pos,b.end(),x)-b.begin());//大于或等于val的第一个元素位置
if (pos==a_size)break;//如果都比这个数小那么返回的pos==数组大小
pos++;
sum+=x;
x*=;
}
return sum;
}
int main()
{
int n;
int tmp;
int mx=;
p.clear();
scanf("%d",&n);
for (int i=; i<=n; i++)
{
scanf("%d",&tmp);
if (p[tmp]==)
{
a.push_back(tmp);
}
p[tmp]++;
mx=max(mx,p[tmp]);
}
b_size=a_size=a.size();
for(int i=; i<a_size; i++)
{
b.push_back(p[a[i]]);
}
sort(b.begin(),b.end());
int ans=;
for (int i=; i<=mx; i++)
{
ans=max(ans,check(i));
}
printf("%d\n",ans);
return ;
}

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个元素传递过来。

代码如下:

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#define ll long long
using namespace std;
ll a[];
ll dp[][];
const ll inf = 0x3f3f3f3f;
int main()
{
ll n,k,x;
scanf("%lld%lld%lld",&n,&k,&x);
{
for(int i=; i<=n; i++)
{
scanf("%lld",&a[i]);
}
memset(dp,-inf,sizeof(dp));
dp[][]=;
//dp[i][j]前i个选出j个
for(int i=; i<=n; i++)//前i个选出l+1个
{
for(int j=i-; j>=max((ll),i-k); j--)//从前i-k位到i-1位,选出l个加上i位置选出a[i]
{
for(int l=; l<x; l++)
dp[i][l+]=max(dp[i][l+],dp[j][l]+a[i]);
}
}
ll maxn;
maxn=-;
for (int i=n; i>n-k; i--)
{
maxn=max(dp[i][x],maxn);
}
printf("%lld\n",maxn);
}
return ;
}

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. 深入了解IOC

    老师在简书写的一篇博客 https://www.jianshu.com/p/79f8331e1f24

  2. SQL Server 索引重建手册

    注意: 索引重建前建议把数据库切换为完整模式,否则索引复制会在数据文件中进行,导致数据文件很大,而数据文件的收缩比日志文件的收缩要困难的多,且会对业务造成影响. 步骤一: 查询索引碎片,脚本如下,库比 ...

  3. Linux CFS调度器之pick_next_task_fair选择下一个被调度的进程--Linux进程的管理与调度(二十八)

    1. CFS如何选择最合适的进程 每个调度器类sched_class都必须提供一个pick_next_task函数用以在就绪队列中选择一个最优的进程来等待调度, 而我们的CFS调度器类中, 选择下一个 ...

  4. Linux进程启动过程分析do_execve(可执行程序的加载和运行)---Linux进程的管理与调度(十一)

    execve系统调用 execve系统调用 我们前面提到了, fork, vfork等复制出来的进程是父进程的一个副本, 那么如何我们想加载新的程序, 可以通过execve来加载和启动新的程序. x8 ...

  5. 4. svg学习笔记-文档结构元素和样式的使用

    svg除了绘图元素之外还有一部分是专门用于文档结构的,这类元素有<g>,<use>,<defs>,<symbol>等 <g>元素 如果我们仅 ...

  6. 利用python搭建Powersploit powershell脚本站点

    powershell脚本站点的搭建 一.Powersploit Powersploit是一款基于powershell的后渗透(Post-Exploitation)框架,集成大量渗透相关模块和功能. 下 ...

  7. ASP.NET -- WebForm -- 页面生命周期

    ASP.NET -- WebForm --  页面生命周期 ASP.NET 页运行时,此页将经历一个生命周期,在生命周期中将执行一系列处理步骤.这些步骤包括初始化.实例化控件.还原和维护状态.运行事件 ...

  8. 【Tars】腾讯微服务框架Tars介绍

    目录 1.介绍2.设计思路3.整体架构4.平台特性1. 介绍 Tars是[基于名字服务][使用Tars协议]的高性能[RPC]开发框架,同时配套一体化的[服务治理平台],帮助个人或者企业快速的以微服务 ...

  9. Integer判断大于 == 127时的坑

    在一次判断返回Interger类型的code,  用==结果, 没进去 Integer的值在-128到127时,Integer对象是在IntegerCache.cache产生,会复用已有对象,也就是说 ...

  10. KazaQ's Socks (找规律)

    #include<iostream> using namespace std; #define ll long long ll n, m; ll t; int main(){ while ...