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 ...
随机推荐
- GIS可视化——聚散图
一.简介 随着计算机的发展,浏览器的不断进步与完善,现今大部分浏览渲染效率有了很大的改善, 但是由于浏览器厂商的不同,浏览器种类繁多,性能不一,并且很多用户还使用着不少老的浏览, 那些如IE6.7等的 ...
- Windows下ELK-5.4.3环境搭建
Windows下ELK-5.4.3环境搭建 一.概述 ELK官网 https://www.elastic.co ELK由Elasticsearch.Logstash和Kibana三部分组件组成: El ...
- 使用yum方式在centOS上安装mysql
1.操作系统及MySQL版本 1.1 操作系统版本 CentOS release 6.5 (Final) 1.2 MySQL版本 mysql-5.1.73-3.el6_5.x86_64mysql-li ...
- vue2 axios 接口函数封装
封装 axios 工具,编辑 src/api/index.js 文件 首先,我们要使用 axios 工具,就必须先安装 axios 工具.执行下面的命令进行安装 npm install axios - ...
- android位置布局
fill_parent 设置一个构件的布局为fill_parent将强制性地使构件扩展,以填充布局单元内尽可能多的空间.这跟Windows控件的dockstyle属性大体一致.设置一个顶部布局或控件为 ...
- Spring 小记
本作品由Man_华创作,采用知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议进行许可.基于http://www.cnblogs.com/manhua/上的作品创作. 使用STS新建spr ...
- 栈(C++)
简介: 限定仅在表尾进行插入或删除操作的线性表 表尾端称为栈顶(top),表头端称为栈底(bottom) 特点: 在栈中,后入栈的元素先出栈 C语言版本 用于测试的文件,以及测试结果可以去作者GitH ...
- ck-reset css(2016/5/13)
/**rest by 2016/05/04 */ * {box-sizing: border-box;} *:before,*:after {box-sizing: border-box;} body ...
- java中url正则regex匹配
String regex = "^(?:https?://)?[\\w]{1,}(?:\\.?[\\w]{1,})+[\\w-_/?&=#%:]*$"; 解释说明: ^ : ...
- 嵌入式c语言笔试
1 读程序段,回答问题int main(int argc,char *argv[]){int c=9,d=0;c=c++%5;d=c;printf("d=%d\n",d);retu ...