【Educational Codeforces Round28】
咸鱼选手发现自己很久不做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】的更多相关文章
- 【Educational Codeforces Round20】
这场edu有点简单…… 所以题目可能也有点奇奇怪怪的. A.随意构造一下,可以发现只有当填满都不行时才可能无解. #include<bits/stdc++.h> using namespa ...
- 【Educational Codeforces Round 38 (Rated for Div. 2)】 Problem A-D 题解
[比赛链接] 点击打开链接 [题解] Problem A Word Correction[字符串] 不用多说了吧,字符串的基本操作 Problem B Run for your prize[贪心] ...
- 【 Educational Codeforces Round 51 (Rated for Div. 2) F】The Shortest Statement
[链接] 我是链接,点我呀:) [题意] [题解] 先处理出来任意一棵树. 然后把不是树上的边处理出来 对于每一条非树边的点(最多21*2个点) 在原图上,做dijkstra 这样就能处理出来这些非树 ...
- 【Educational Codeforces Round 53 (Rated for Div. 2) C】Vasya and Robot
[链接] 我是链接,点我呀:) [题意] [题解] 如果|x|+|y|>n 显然.从(0,0)根本就没法到(x,y) 但|x|+|y|<=n还不一定就能到达(x,y) 注意到,你每走一步路 ...
- 【Educational Codeforces Round 48 (Rated for Div. 2) C】 Vasya And The Mushrooms
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 显然在没有一直往右走然后走到头再往上走一格再往左走到头之前. 肯定是一直在蛇形走位.. 这个蛇形走位的答案贡献可以预处理出来.很容易 ...
- 【Educational Codeforces Round 48 (Rated for Div. 2) D】Vasya And The Matrix
[链接] 我是链接,点我呀:) [题意] 告诉你每一行.每一列的异或和. 让你求出一个符合要求的原矩阵. [题解] 显然应该有 a1^a2^....^an = b1^b2^....^bn 也即两边同时 ...
- 【Educational Codeforces Round 41 (Rated for Div. 2) D】Pair Of Lines
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 如果点的个数<=3 那么直接输出有解. 否则. 假设1,2最后会在一条直线上,则把这条直线上的点都删掉. 看看剩余的点是否在同 ...
- 【Educational Codeforces Round 37 F】SUM and REPLACE
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 那个D函数它的下降速度是很快的. 也就是说到最后他会很快的变成2或者1 而D(2)==2,D(1)=1 也就是说,几次操作过后很多数 ...
- 【Educational Codeforces Round 37 E】Connected Components?
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] bfs. 用一个链表来记录哪些点已经确定在某一个联通快里了. 一开始每个点都能用. 然后从第一个点开始进行bfs. 然后对于它的所有 ...
随机推荐
- BZOJ 1014 火星人 | 平衡树维护哈希
BZOJ 1014 火星人 题意 有一个字符串,三中操作:在某位置后面插入一个字符.修改某位置的字符.询问两个后缀的最长公共前缀. 题解 看到网上的dalao们都说这道题是平衡树,我就很懵x--平衡树 ...
- 数字表格(product)
Description Solution 一开始的时候我是这么推的(\(f(n)\)表示斐波那契数列的第\(n\)项) \[ \begin{aligned} Ans&=\prod_{x=1}^ ...
- Linux kernel(CVE-2018-17182)提权漏洞复现
0x01 漏洞前言 Google Project Zero的网络安全研究人员发布了详细信息,并针对自内核版本3.16到4.18.8以来Linux内核中存在的高严重性漏洞的概念验证(PoC)漏洞利用.由 ...
- Web项目开发中用到的缓存技术
在WEB开发中用来应付高流量最有效的办法就是用缓存技术,能有效的提高服务器负载性能,用空间换取时间.缓存一般用来 存储频繁访问的数据 临时存储耗时的计算结果 内存缓存减少磁盘IO 使用缓存的2个主要原 ...
- 解题:洛谷2093 JZPFAR
题面 初见K-D Tree 其实这样的题(欧几里得距离第$x$近点对)不应该用K-D Tree做,因为会被构造数据卡成$O(n^2)$,随机的另说. 但是并没有找到合适的K-D Tree的题(区域统计 ...
- linux kill 掉所有匹配到名字的进程
如,要 kill 掉 swoole 相关的进程 ps aux | grep swoole | awk '{print $2}' | xargs kill -9 ps 列出所有进程, 参数: a - ...
- 梯度提升树GBDT算法
转自https://zhuanlan.zhihu.com/p/29802325 本文对Boosting家族中一个重要的算法梯度提升树(Gradient Boosting Decison Tree, 简 ...
- Excel批量删除换行符_clean函数
http://jingyan.baidu.com/article/e2284b2b489b96e2e6118d30.html CLEAN函数,用于删除文本中不能打印的字符.对从其他应用程序中输入的文本 ...
- Xcode关闭警告
对于关闭某个警告,如果需要全局关闭的话,直接在Other C Flags里写 -Wno-...就行了,比如 -Wextra -Wno-sign-compare 就是一个常见的组合.如果相对某几个文件开 ...
- 科学计算三维可视化---TraitsUI(控件)
一:文本编辑器 from traits.api import HasTraits,Int,Str,Password from traitsui.api import View,Item,Group,M ...