Codeforces 1236D. Alice and the Doll
注意到每个位置只能右转一次,首先考虑如果图没有障碍那么显然要走螺旋形的
然后现在有障碍,容易发现对于某个位置如果既可以直走又可以右转,那么一定会选择直走
因为如果转了以后就一定没法走到原本直走可以走到的位置,所以必须直走
那么思路就很明确了,按这种走法然后看看走到底以后经过的总的格子数是不是等于没有障碍的格子数
但是暴力显然会 $T$ 飞
所以对每一行每一列维护一个 $vector$ ,每次走直接在 $vector$ 上二分出第一个走到的障碍,然后就可以了
实现的时候会注意到走过的位置会因为没有障碍重复走
但是因为我们在绕圈的时候走的矩形是越来越小的,所以维护一下外层的矩形就行了
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
using namespace std;
typedef long long ll;
inline int read()
{
int x=,f=; char ch=getchar();
while(ch<''||ch>'') { if(ch=='-') f=-; ch=getchar(); }
while(ch>=''&&ch<='') { x=(x<<)+(x<<)+(ch^); ch=getchar(); }
return x*f;
}
const int N=1e5+;
int n,m,K;
ll ans;
vector <int> X[N],Y[N];
int main()
{
n=read(),m=read(),K=read();
for(int i=;i<=K;i++)
{
int a=read(),b=read();
X[a].push_back(b); Y[b].push_back(a);
}
for(int i=;i<=n;i++) sort(X[i].begin(),X[i].end());
for(int i=;i<=m;i++) sort(Y[i].begin(),Y[i].end());
int x=,y=,k=,flag=; ans++;
int xL=,xR=n+,yL=,yR=m+;
while()
{
int tx=,ty=;
if(k==)
{
tx=x,ty=lower_bound(X[x].begin(),X[x].end(),y)-X[x].begin();
if(ty==X[x].size()) ty=yR-;
else ty=min(yR-,X[x][ty]-);
k=; xL=x;
}
else if(k==)
{
tx=lower_bound(Y[y].begin(),Y[y].end(),x)-Y[y].begin(),ty=y;
if(tx==Y[y].size()) tx=xR-;
else tx=min(xR-,Y[y][tx]-);
k=; yR=y;
}
else if(k==)
{
tx=x,ty=lower_bound(X[x].begin(),X[x].end(),y)-X[x].begin()-;
if(ty<) ty=yL+;
else ty=max(yL+,X[x][ty]+);
k=; xR=x;
}
else if(k==)
{
tx=lower_bound(Y[y].begin(),Y[y].end(),x)-Y[y].begin()-,ty=y;
if(tx<) tx=xL+;
else tx=max(xL+,Y[y][tx]+);
k=; yL=y;
}
if(x==tx&&y==ty&&flag) break;
ans+=abs(x-tx)+abs(y-ty); x=tx,y=ty;
flag=;
}
if(ans>1ll*n*m-K) cout<<"GG";
if(ans==1ll*n*m-K) printf("Yes\n");
else printf("No\n");
return ;
}
Codeforces 1236D. Alice and the Doll的更多相关文章
- [CF1236D] Alice and the Doll - 模拟,STL
[CF1236D] Alice and the Doll Description \(N \times M\)网格,有 \(K\) 个格子里有障碍物.每次经过一个格子的时候只能直走或者右转一次.初态在 ...
- Codeforces Round #593 (Div. 2) D. Alice and the Doll
题目:http://codeforces.com/problemset/problem/1236/D思路:机器人只能按照→↓←↑这个规律移动,所以在当前方向能够前进的最远处即为界限,到达最远处右转,并 ...
- Codeforces - 346A - Alice and Bob - 简单数论
http://codeforces.com/problemset/problem/346/A 观察了一下,猜测和他们的最大公因数有关,除以最大公因数前后结果是不会变的. 那么怎么证明一定是有n轮呢?我 ...
- CodeForces 346A Alice and Bob (数学最大公约数)
题意:有一堆数,然后有两个人轮流从中取出两个数,这两个数的差的绝对值不在这个集合,然后把这个数放进这个集合,如果哪个人不能拿了,就是输了,问你谁赢. 析:当时连题意都没看好,以为拿出两个数,就不放回了 ...
- Codeforces 1236F - Alice and the Cactus(期望+分类讨论)
Codeforces 题面传送门 & 洛谷题面传送门 期望好题. 首先拆方差: \[\begin{aligned} &E((x-E(x))^2)\\ =&E(x^2)-2E(x ...
- CodeForces 1236D(模拟)
题意 https://vjudge.net/problem/CodeForces-1236D 最近,爱丽丝得到了一个新玩偶.它甚至可以走路! 爱丽丝为玩偶建造了一个迷宫,并想对其进行测试.迷宫具有n行 ...
- Codeforces 1236E. Alice and the Unfair Game
传送门 首先可以注意到对于固定的起点 $S$ ,它最终能走到的终点一定是一段区间 这个用反证法容易证明,假设合法区间存在断点,这个点左右都可以作为终点 那么分成区间断点在起点左边和起点右边讨论一下即可 ...
- Codeforces 1236B. Alice and the List of Presents
传送门 显然每种礼物是互相独立的,一个礼物的分配不会影响另一个礼物 对于某个礼物 $x$ , 对于每个盒子来说,要么选要么不选,那么可以看成长度为 $m$ 的二进制序列 这个序列第 $i$ 位的数就代 ...
- 【CF1236D】Alice and the Doll(set)
题意:给定一个n*m的网格,其中k格有障碍 周驿东从(1,1)出发面朝右,每次行动前他可以选择顺时针旋转90度或不旋转,然后向自己朝向的位置走1格 问他能否不重复不遗漏的走过所有非障碍格 n,m,k& ...
随机推荐
- springMVC配置拦截器、过滤器、前端控制器时遇到的问题总结
1.业务场景:使用vuejs+springMVC+spring框架搭建一个mis系统,集成SSO单点登录: 2.遇到问题:使用interceptor拦截器配置SSO单点登录,直接敲域名,或者ip+端口 ...
- Python list 遇到的问题
1.list“+” 运算 <list += > diff. <ndarray +=> list1 += list2是追加,而不是加法运算 list1 = [0,0,0] lis ...
- POJ 2109 -- Power of Cryptography
Power of Cryptography Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 26622 Accepted: ...
- JDBC与ODBC
ODBC(Open Database Connectivity)是一组对数据库访问的标准API,这些API通过SQL来完成大部分任务,而且它本身也支持SQL语言,支持用户发来的SQL.ODBC定义了 ...
- 前端知识点回顾——Javascript篇(六)
fetch 在原生ajax+es6promise的基础上封装的一个语法糖,返回promise对象. fetch(url, initObj) .then(res=>res.json()) .the ...
- 前端知识点回顾之重点篇——CORS
CORS(cross origin resource sharing)跨域资源共享 来源:http://www.ruanyifeng.com/blog/2016/04/cors.html 它允许浏览器 ...
- LC 957. Prison Cells After N Days
There are 8 prison cells in a row, and each cell is either occupied or vacant. Each day, whether the ...
- django中iframe问题
因为在django中无法识别我们普通的url格式,比如使用<iframe src="articles.html"></iframe>,这种格式django无 ...
- Smarty模板实现隔行换样式
在网上找了好多关于隔行改变样式的文章,都不符合自己的要求,所以自己想了好多办法,终于把隔行改变样式拿下! 这是模板文件中商品分类列表 <!--{foreach from=$cat ...
- PCL中有哪些可用的PointT类型(3)
博客转载自:http://www.pclcn.org/study/shownews.php?lang=cn&id=268 PointXYZRGBNormal - float x, y, z, ...