Codeforces Round #551 (Div. 2) A~E题解

突然发现上一场没有写,那就补补吧

本来这场应该5题的,结果一念之差E fail了

A. Serval and Bus

基本数学不解释,假如你没有+1 -1真的不好意思见人了

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
const int _=1e2; int s[],d[];
int main()
{
int n,T,mn=;
scanf("%d%d",&n,&T);
for(int i=;i<=n;i++)
{
scanf("%d%d",&s[i],&d[i]);
if(s[i]<T)
{
s[i]+=((T-s[i]-)/d[i]+)*d[i];
}
if(mn==||s[i]<s[mn])mn=i;
}
printf("%d\n",mn); return ;
}

A. Serval and Bus

B. Serval and Toy Bricks

直接行列取min完事

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
const int _=1e2; int a[],b[],c[][];
int main()
{
int n,m,h;
scanf("%d%d%d",&n,&m,&h);
for(int i=;i<=m;i++)scanf("%d",&a[i]);
for(int i=;i<=n;i++)scanf("%d",&b[i]);
for(int i=;i<=n;i++)
for(int j=;j<=m;j++)
scanf("%d",&c[i][j]); for(int i=;i<=n;i++)
{
for(int j=;j<=m;j++)
{
if(c[i][j]==)printf("");
else
{
printf("%d",min(b[i],a[j]));
}
putchar(j==m?'\n':' ');
}
} return ;
}

B. Serval and Toy Bricks

C. Serval and Parenthesis Sequence

这题明显乱搞了,场上看错题意又写了个假的做法,最后迷迷糊糊乱搞了出来。

就是(不足n/2就先放就没了,这种东西都fail了两发

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std; char ss[]; int num[];
int main()
{
int n;
scanf("%d%s",&n,ss+);
if(n%==){puts(":(");return ;}
for(int i=n;i>=;i--)num[i]=num[i+]+(ss[i]=='('?:);
int le=,s=;
for(int i=;i<=n;i++)
{
if(ss[i]=='(')le++,s++;
else if(ss[i]==')')
{
if(le>)
{
le--;
if(le==&&i!=n){puts(":(");return ;}
}
else {puts(":(");return ;}
}
else
{
if(s+num[i+]<n/)ss[i]='(',le++,s++;
else
{
ss[i]=')',le--;
if(le==&&i!=n){puts(":(");return ;}
}
}
}
if(s>n/){puts(":(");return ;}
for(int i=;i<=n;i++)printf("%c",ss[i]); return ;
}

C. Serval and Parenthesis Sequence

D. Serval and Rooted Tree

这个题明显就是见过的套路,max就是子树max+其他子树的tot,min就是每个子树都取到max-1再+1

先是以为min是取max(子树max)wa了,然后又没用maxn搞的数组少一个0,这个时候心态已经崩了,zory 50min之前就做完了A~D

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std; struct node
{
int x,y,next;
}a[];int len,last[];
void ins(int x,int y)
{
len++;
a[len].x=x;a[len].y=y;
a[len].next=last[x];last[x]=len;
}
int op[],le[],mx[];
void dfs(int x)
{
if(last[x]==)le[x]=,mx[x]=;
else
{
if(op[x]==)
{
int p1=;
for(int k=last[x];k;k=a[k].next)
{
int y=a[k].y;
dfs(y);
le[x]+=le[y];
if(p1==||mx[y]-le[y]>mx[p1]-le[p1])p1=y;
}
mx[x]=le[x]-le[p1]+mx[p1];
}
else
{
int num=;
for(int k=last[x];k;k=a[k].next)
{
int y=a[k].y;
dfs(y);
le[x]+=le[y];
num+=mx[y]-;
}
mx[x]=num+;
}
}
} int main()
{
int n;
scanf("%d",&n);
for(int i=;i<=n;i++)scanf("%d",&op[i]);
int F;
for(int i=;i<=n;i++)
{
scanf("%d",&F);
ins(F,i);
}
dfs();
printf("%d\n",mx[]); return ;
}

D. Serval and Rooted Tree

E. Serval and Snake

结果突然不困了,发现这个E是个SB题,假如这个矩形里面有头或尾之一,那么他的度数就是1,直接枚举行列就可以定位,对于两个点在同一行/列的二分答案就好了,结果写萎了要算2020次正好被卡飞,第二天就被rose_king D飞了

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std; bool check1(int t,int x,int y)
{
printf("? %d %d %d %d\n",t,x,t,y);
fflush(stdout);
int k;scanf("%d",&k);
return k%==;
}
bool check2(int t,int x,int y)
{
printf("? %d %d %d %d\n",x,t,y,t);
fflush(stdout);
int k;scanf("%d",&k);
return k%==;
}
int main()
{
int n;
scanf("%d",&n); int ax,ay,bx,by,k,op=;
for(int i=;i<=n;i++)
{
if(i==n&&op==)break;
printf("? 1 1 %d %d\n",i,n);
fflush(stdout); scanf("%d",&k);
if(k%==&&op==)
{
ax=i;
int l=,r=n;
while(l<=r)
{
int mid=(l+r)/;
if(check1(i,l,mid))r=mid;
else l=mid+;
if(l==r){ay=l;break;}
}
op=;
}
if(k%==&&op==)
{
bx=i;
int l=,r=n;
while(l<=r)
{
int mid=(l+r)/;
if(check1(i,l,mid))r=mid;
else l=mid+;
if(l==r){by=l;break;}
}
printf("! %d %d %d %d\n",ax,ay,bx,by);
fflush(stdout);
return ;
}
}
op=;
for(int j=;j<=n;j++)
{
printf("? 1 1 %d %d\n",n,j);
fflush(stdout); scanf("%d",&k);
if(k%==&&op==)
{
ay=j;
int l=,r=n;
while(l<=r)
{
int mid=(l+r)/;
if(check2(j,l,mid))r=mid;
else l=mid+;
if(l==r){ax=l;break;}
}
op=;
}
if(k%==&&op==)
{
by=j;
int l=,r=n;
while(l<=r)
{
int mid=(l+r)/;
if(check2(j,l,mid))r=mid;
else l=mid+;
if(l==r){bx=l;break;}
}
printf("! %d %d %d %d\n",ax,ay,bx,by);
fflush(stdout);
return ;
}
} return ;
}

E. Serval and Snake

结果zory A fail了都比我高。。

上一篇:【Codeforces】Codeforces Round #551 (Div. 2)


下一篇:Leetcode: Design Snake Game