【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. 然后对于它的所有 ...
随机推荐
- uoj132/BZOJ4200/洛谷P2304 [Noi2015]小园丁与老司机 【dp + 带上下界网络流】
题目链接 uoj132 题解 真是一道大码题,,,肝了一个上午 老司机的部分是一个\(dp\),观察点是按\(y\)分层的,而且按每层点的上限来看可以使用\(O(nd)\)的\(dp\),其中\(d\ ...
- P2870 [USACO07DEC]最佳牛线,黄金Best Cow Line, Gold 解题报告
P2870 [USACO07DEC]最佳牛线,黄金Best Cow Line, Gold 题意 给一个字符串,每次可以从两边中的一边取一个字符,要求取出的字符串字典序最小 可以Hash+二分 也可以S ...
- ActiveMQ反序列化漏洞(CVE-2015-5254)复现
0x00 漏洞前言 Apache ActiveMQ是美国阿帕奇(Apache)软件基金会所研发的一套开源的消息中间件,它支持Java消息服务,集群,Spring Framework等.Apache ...
- phpredis pipeline
通过pipeline方式将client端命令一起发出,redis server会处理完多条命令后,将结果一起打包返回client,从而节省大量的网络延迟开销.
- android:onClick="xxx"
一般监听OnClickListener事件,我们都是通过Button button = (Button)findViewById(....); button.setOClickLisener....这 ...
- 4:JAVA UUID 生成
GUID是一个128位长的数字,一般用16进制表示.算法的核心思想是结合机器的网卡.当地时间.一个随即数来生成GUID.从理论上讲,如果一台机器每秒产生10000000个GUID,则可以保证(概率意义 ...
- codeforces.com/contest/251/problem/C
C. Number Transformation time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- 【Asp.net入门5-01】SportsStore:一个真实的应用程序
- Cloudstack安装(二)
Cloudstack安装 官方文档参考: http://docs.cloudstack.apache.org/projects/cloudstack-installation/en/4.9/qig.h ...
- Hadoop生态圈-HBase性能优化
Hadoop生态圈-HBase性能优化 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任.