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 Round #551 (Div. 2) A~E题解的更多相关文章
- 【Codeforces】Codeforces Round #551 (Div. 2)
Codeforces Round #551 (Div. 2) 算是放弃颓废决定好好打比赛好好刷题的开始吧 A. Serval and Bus 处理每个巴士最早到站且大于t的时间 #include &l ...
- Codeforces Round #612 (Div. 2) 前四题题解
这场比赛的出题人挺有意思,全部magic成了青色. 还有题目中的图片特别有趣. 晚上没打,开virtual contest打的,就会前三道,我太菜了. 最后看着题解补了第四道. 比赛传送门 A. An ...
- Codeforces Round #198 (Div. 2)A,B题解
Codeforces Round #198 (Div. 2) 昨天看到奋斗群的群赛,好奇的去做了一下, 大概花了3个小时Ak,我大概可以退役了吧 那下面来稍微总结一下 A. The Wall Iahu ...
- Codeforces Round #672 (Div. 2) A - C1题解
[Codeforces Round #672 (Div. 2) A - C1 ] 题目链接# A. Cubes Sorting 思路: " If Wheatley needs more th ...
- Codeforces Round #551 (Div. 2) 题解
CF1153A 直接做啊,分类讨论即可 #include<iostream> #include<string.h> #include<string> #includ ...
- Codeforces Round #551 (Div. 2) E 二分 + 交互
https://codeforces.com/contest/1153/problem/E 题意 边长为n的正方形里面有一条蛇,每次可以询问一个矩形,然后会告诉你蛇身和矩形相交有几部分,你需要在最多2 ...
- Codeforces Round #551 (Div. 2) D 树形dp
https://codeforces.com/contest/1153/problem/D 题意 一颗有n个点的数,每个点a[i]为0代表取子节点的最小,1代表取最大,然后假设树上存在k个叶子,问你如 ...
- Codeforces Round #614 (Div. 2) A-E简要题解
链接:https://codeforces.com/contest/1293 A. ConneR and the A.R.C. Markland-N 题意:略 思路:上下枚举1000次扫一遍,比较一下 ...
- Codeforces Round #610 (Div. 2) A-E简要题解
contest链接: https://codeforces.com/contest/1282 A. Temporarily unavailable 题意: 给一个区间L,R通有网络,有个点x,在x+r ...
随机推荐
- docker入门小结(三)
本次笔记主要记录教程中的几个实战案例的实际情况 1,使用supervisor管理进程 忘了截图了,就不写了.教程中写的比较清楚. 但是注意,如果刚刚学习了上一章的网络配置,需要将网络的forward打 ...
- 通过run configuration启动项目
系统通过配置加载路径是通过classpath加载绝对路径 设置属性选中某个项目,然后在工具栏中选择"Run-->Run Confgurations“,然后在对话框的右边选择" ...
- Micro:Bit手柄试用之一MagicPad (解决蓝牙与gamePad包共存)
前言 原创文章,转载引用务必注明链接.由于本人初次接触Micro:Bit,水平有限,如有疏漏,欢迎指正. Micro:Bit真好玩! DFRobot的论坛相关资料算是国内比较丰富的了,个人感觉MB比A ...
- cocos2d-x 3.0游戏实例学习笔记 《跑酷》移植到android手机
说明:这里是借鉴:晓风残月前辈的博客.他是将泰然网的跑酷教程.用cocos2d-x 2.X 版本号重写的,眼下我正在学习cocos2d-X3.0 于是就用cocos2d-X 3.0重写,并做相关笔记 ...
- 对于Json和对象转换的学习
学习这个的用处有非常多的: 在传输数据过程中比較查看数据比較清晰,代码也较清晰.也能够避免split函数带来的隐藏bug 当然也有不足: 准备工具较繁琐,须要准备对象(当然 ...
- Android VS IOS
时间: IOS:var d = new Date("2018-04-19 14:23:00".replace(/-/g, "/")); (d = new Dat ...
- nodejs读取配置文件
INI.js(模块) var eol = process.platform === "win32" ? "\r\n" : "\n" func ...
- IDEA小技巧-随时更新
© 版权声明:本文为博主原创文章,转载请注明出处 1.设置删除一行快捷键 File->Settings->keymap->Delete Line 2.设置代码提示快捷键 File-& ...
- Hibernate demo之使用注解
1.新建maven项目 testHibernate,pom.xml <?xml version="1.0" encoding="UTF-8"?> & ...
- CocoaPods安装教程 pod setup很慢解决方案
CocoaPods安装教程 pod setup很慢解决方案 http://www.jianshu.com/p/6230eec137f6