咸鱼选手发现自己很久不做cf了,晚节不保。

A.Curriculum Vitae

枚举一下间断点的位置。

#include<bits/stdc++.h>
using namespace std;
const int N=;
int cnt,n,a[N],mx,cur;
inline int read(){
int f=,x=;char ch;
do{ch=getchar();if(ch=='-')f=-;}while(ch<''||ch>'');
do{x=x*+ch-'';ch=getchar();}while(ch>=''&&ch<='');
return f*x;
}
int main(){
n=read();
for(int i=;i<=n;i++)a[i]=read();
int flag=;
for(int i=;i<=n;i++){
cur=;for(int j=;j<=i;j++)if(a[j]==)cur++;
for(int j=i;j<=n;j++)if(a[j]==)cur++;
mx=max(mx,cur);
}
printf("%d\n",mx);
}

B. Math Show

枚举完成了哪些套装,然后剩下的贪心算就好。

#include<bits/stdc++.h>
const int N=;
typedef long long ll;
using namespace std;
int n,m;
ll a[N],cur,tot,ans,qwq,k;
int vis[N];
inline ll read(){
ll f=,x=;char ch;
do{ch=getchar();if(ch=='-')f=-;}while(ch<''||ch>'');
do{x=x*+ch-'';ch=getchar();}while(ch>=''&&ch<='');
return f*x;
} int main(){
n=read();k=read();m=read();
for(int i=;i<=k;i++)a[i]=read(),tot+=a[i];
sort(a+,a+k+);
if(m>=tot*n){
ans=1LL*n*(k+);cout<<ans<<endl;return ;
}
for(int i=;i<=n;i++){
ll res=m-1LL*i*tot;
if(res<)continue;
ll cur=;cur+=1LL*i*(k+);ll qwq=n-i;
if(res==){ans=max(ans,cur);continue;}
for(int j=;j<=k;j++){
if(qwq*a[j]<=res){res-=qwq*a[j];cur+=qwq;if(res<=)break;continue;}
if(res<=)break;
ll q=res/a[j];cur+=q;break;
}
ans=max(ans,cur);
}
cout<<ans<<endl;
}

老年选手晚节不保,一开始还以为尽量多做整套。

我是傻逼。

C. Four Segments

化简一下式子,然后就可以枚举了。

#include<bits/stdc++.h>
typedef long long ll;
const int N=;
using namespace std;
ll s[N],n,ans,x,y,z;
inline ll read(){
ll f=,x=;char ch;
do{ch=getchar();if(ch=='-')f=-;}while(ch<''||ch>'');
do{x=x*+ch-'';ch=getchar();}while(ch>=''&&ch<='');
return f*x;
}
int main(){
n=read();
for(int i=;i<=n;i++)s[i]=s[i-]+read();
for(int i=;i<=n;i++){
ll cur=s[i],now=i;
for(int j=i;j<=n;j++){
if(s[j]<cur)cur=s[j],now=j;
if(s[i]-s[now]+s[j]>ans)ans=s[i]-s[now]+s[j],x=i,y=now,z=j;
}
}
printf("%I64d %I64d %I64d\n",x,y,z);
}

D. Monitor

维护一个二维的前缀和。然后做k次拓展,这样每个点管的就是一个向上k的矩形。

剩下的就是横向的区间max,500的范围老年选手选择失去梦想的n^3暴力。

#include<bits/stdc++.h>
const int N=;
using namespace std;
int n,m,k,q,inf;
int a[N][N];
struct Point{int x,y,t;}p[];
inline int read(){
int f=,x=;char ch;
do{ch=getchar();if(ch=='-')f=-;}while(ch<''||ch>'');
do{x=x*+ch-'';ch=getchar();}while(ch>=''&&ch<='');
return f*x;
}
inline int querymax(int o,int l,int r){
int ans=;
for(int i=l;i<=r;i++)ans=max(a[o][i],ans);
return ans;
}
int ans=;
int main(){
n=read();m=read();k=read();q=read();
memset(a,,sizeof(a));inf=a[][];ans=inf;
for(int i=;i<=q;i++){
p[i].x=read();p[i].y=read();p[i].t=read();
a[p[i].x][p[i].y]=p[i].t;
}
for(int qwq=;qwq<k;qwq++)
for(int i=;i<n;i++)for(int j=;j<=m;j++)a[i][j]=max(a[i][j],a[i+][j]);
for(int i=;i+k-<=n;i++)for(int j=;j+k-<=m;j++)
ans=min(ans,querymax(i,j,j+k-));
if(ans==inf)puts("-1");else printf("%d\n",ans);
}

E. Chemistry in Berland

关系会形成一棵树,这很显然。

然后就是考虑节点之间的关系,这个关系其实就是树的拓扑序,一边对树拓扑排序一边dp一下,从下面开始先试图用父亲节点满足子节点

多余的上传到父亲节点即可。

#include<bits/stdc++.h>
const int N=;
typedef long long ll;
const ll inf=(1LL<<)-;
using namespace std;
ll a[N],b[N],dp[N];
int n,m,tot,head[N];
struct Edge{int u,v,next;ll w;}G[N<<];
inline void addedge(int u,int v,ll w){
G[++tot].u=u;G[tot].v=v;G[tot].w=w;G[tot].next=head[u];head[u]=tot;
G[++tot].u=v;G[tot].v=u;G[tot].w=w;G[tot].next=head[v];head[v]=tot;
}
inline void dfs(int u,int f){
dp[u]=b[u]-a[u];
for(int i=head[u];i;i=G[i].next){
int v=G[i].v;ll w=G[i].w;
if(v==f)continue;
dfs(v,u);
if(dp[v]<){
if(-dp[v]<inf/w)dp[u]+=dp[v]*w;
else dp[u]=-inf;
if(dp[u]<-inf)dp[u]=-inf;
}
else dp[u]+=dp[v];
}
}
inline ll read(){
ll f=,x=;char ch;
do{ch=getchar();if(ch=='-')f=-;}while(ch<''||ch>'');
do{x=x*+ch-'';ch=getchar();}while(ch>=''&&ch<='');
return f*x;
}
int main(){
n=read();
for(int i=;i<=n;i++)b[i]=read();
for(int i=;i<=n;i++)a[i]=read();
for(int i=;i<=n;i++){
int x=read();ll k=read();
addedge(i,x,k);
}
dfs(,);
puts(dp[]>=?"YES":"NO");
}

F. Random Query

这种题栋老师怕不是随便秒。

考虑一个数对区间的贡献,重复的数记录最后一次出现的位置,最后除所有可能即可。

#include<bits/stdc++.h>
const int N=;
typedef long long ll;
using namespace std;
int n,m,a[N],b[N];
ll ans=;
inline int read(){
int f=,x=;char ch;
do{ch=getchar();if(ch=='-')f=-;}while(ch<''||ch>'');
do{x=x*+ch-'';ch=getchar();}while(ch>=''&&ch<='');
return f*x;
}
int main(){
n=read();
for(int i=;i<=n;i++)a[i]=read();
ll ans=,t=;
for(int i=;i<=n;i++){
t+=i-b[a[i]];ans+=t;b[a[i]]=i;
}
printf("%.6lf\n",(ans*-n)/(double)(1LL*n*n));
}

总结:

1.注意想清楚特判,在提交之前想清楚所有可能情况以及特殊、极端的情况,不要想当然,防止晚节不保

2.看清楚数据范围,做多次确认。

【Educational Codeforces Round28】的更多相关文章

  1. 【Educational Codeforces Round20】

    这场edu有点简单…… 所以题目可能也有点奇奇怪怪的. A.随意构造一下,可以发现只有当填满都不行时才可能无解. #include<bits/stdc++.h> using namespa ...

  2. 【Educational Codeforces Round 38 (Rated for Div. 2)】 Problem A-D 题解

    [比赛链接] 点击打开链接 [题解] Problem A Word Correction[字符串] 不用多说了吧,字符串的基本操作 Problem B  Run for your prize[贪心] ...

  3. 【 Educational Codeforces Round 51 (Rated for Div. 2) F】The Shortest Statement

    [链接] 我是链接,点我呀:) [题意] [题解] 先处理出来任意一棵树. 然后把不是树上的边处理出来 对于每一条非树边的点(最多21*2个点) 在原图上,做dijkstra 这样就能处理出来这些非树 ...

  4. 【Educational Codeforces Round 53 (Rated for Div. 2) C】Vasya and Robot

    [链接] 我是链接,点我呀:) [题意] [题解] 如果|x|+|y|>n 显然.从(0,0)根本就没法到(x,y) 但|x|+|y|<=n还不一定就能到达(x,y) 注意到,你每走一步路 ...

  5. 【Educational Codeforces Round 48 (Rated for Div. 2) C】 Vasya And The Mushrooms

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 显然在没有一直往右走然后走到头再往上走一格再往左走到头之前. 肯定是一直在蛇形走位.. 这个蛇形走位的答案贡献可以预处理出来.很容易 ...

  6. 【Educational Codeforces Round 48 (Rated for Div. 2) D】Vasya And The Matrix

    [链接] 我是链接,点我呀:) [题意] 告诉你每一行.每一列的异或和. 让你求出一个符合要求的原矩阵. [题解] 显然应该有 a1^a2^....^an = b1^b2^....^bn 也即两边同时 ...

  7. 【Educational Codeforces Round 41 (Rated for Div. 2) D】Pair Of Lines

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 如果点的个数<=3 那么直接输出有解. 否则. 假设1,2最后会在一条直线上,则把这条直线上的点都删掉. 看看剩余的点是否在同 ...

  8. 【Educational Codeforces Round 37 F】SUM and REPLACE

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 那个D函数它的下降速度是很快的. 也就是说到最后他会很快的变成2或者1 而D(2)==2,D(1)=1 也就是说,几次操作过后很多数 ...

  9. 【Educational Codeforces Round 37 E】Connected Components?

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] bfs. 用一个链表来记录哪些点已经确定在某一个联通快里了. 一开始每个点都能用. 然后从第一个点开始进行bfs. 然后对于它的所有 ...

随机推荐

  1. 【刷题】BZOJ 2588 Spoj 10628. Count on a tree

    Description 给定一棵N个节点的树,每个点有一个权值,对于M个询问(u,v,k),你需要回答u xor lastans和v这两个节点间第K小的点权.其中lastans是上一个询问的答案,初始 ...

  2. 【刷题】BZOJ 4031 [HEOI2015]小Z的房间

    Description 你突然有了一个大房子,房子里面有一些房间.事实上,你的房子可以看做是一个包含n*m个格子的格状矩形,每个格子是一个房间或者是一个柱子.在一开始的时候,相邻的格子之间都有墙隔着. ...

  3. SpringBoot入门系列HelloWorld

    根据咱们程序员学习的惯例,学习一门新技术都是从HelloWorld开始的. 感觉编程是一件非常富有意义的事情,程序员也是一群可爱的人,渴望被关怀和关注,因为我们总在和世界say Hi. 好了进入正题 ...

  4. 【CF938G】Shortest Path Queries(线段树分治,并查集,线性基)

    [CF938G]Shortest Path Queries(线段树分治,并查集,线性基) 题面 CF 洛谷 题解 吼题啊. 对于每个边,我们用一个\(map\)维护它出现的时间, 发现询问单点,边的出 ...

  5. 51nod 1564 区间的价值 | 分治 尺取法

    51nod 1564 区间的价值 题面 一个区间的价值是区间最大值×区间最小值.给出一个序列\(a\), 求出其中所有长度为k的子区间的最大价值.对于\(k = 1, 2, ..., n\)输出答案. ...

  6. phpredis -- Redis Arrays用法

    Redis Arrays 来自地址:https://github.com/phpredis/phpredis/blob/master/arrays.markdown#readme 扩展原文件array ...

  7. Jenkins(一)---我理解的jenkins是这样的

    1.齿轮 如果将 java / maven / ant / git / tomcat / jenkins 等等软件比喻为齿轮:如下图 两个软件在一起可以驱动另外一个软件:如下图 如果把这些软件要集成在 ...

  8. std::async

    https://www.cnblogs.com/qicosmos/p/3534211.html https://bobjin.com/blog/c_cpp_docs/reference/en/cpp/ ...

  9. apt代理设置

    内网apt使用代理 /etc/apt/apt.conf Acquire::http::Proxy "http://guest:password@ip:port";

  10. c# string 和 byte[]数组之间转换

    在文件流读取和存储过程当中,经常涉及到byte[]数组形式存储数据,再此过程中也涉及到String类型字符串和byte[]的类型转换,下面我们举例说明一下. 现在有一个字符串: string str ...