# 【Educational Codeforces Round28】

A.Curriculum Vitae

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

B. Math Show

#include<bits/stdc++.h>
const int N=50;
typedef long long ll;
using namespace std;
int n,m;
ll a[N],cur,tot,ans,qwq,k;
int vis[N];
ll f=1,x=0;char ch;
do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');
do{x=x*10+ch-'0';ch=getchar();}while(ch>='0'&&ch<='9');
return f*x;
}

int main(){
sort(a+1,a+k+1);
if(m>=tot*n){
ans=1LL*n*(k+1);cout<<ans<<endl;return 0;
}
for(int i=0;i<=n;i++){
ll res=m-1LL*i*tot;
if(res<0)continue;
ll cur=0;cur+=1LL*i*(k+1);ll qwq=n-i;
if(res==0){ans=max(ans,cur);continue;}
for(int j=1;j<=k;j++){
if(qwq*a[j]<=res){res-=qwq*a[j];cur+=qwq;if(res<=0)break;continue;}
if(res<=0)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=1000010;
using namespace std;
ll s[N],n,ans,x,y,z;
ll f=1,x=0;char ch;
do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');
do{x=x*10+ch-'0';ch=getchar();}while(ch>='0'&&ch<='9');
return f*x;
}
int main(){
for(int i=0;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

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

E. Chemistry in Berland

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

F. Random Query

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

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

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

posted @ 2017-09-28 19:08  zcysky  阅读(323)  评论(0编辑  收藏