思路好想,细节多的令人发指。。

/*
反着判断:走完每个点=走过的路程=n*m-k
然后暴力判每行每列的目的地
每次走都能使走的范围缩小一行或者一列
*/
#include<bits/stdc++.h>
#include<vector>
using namespace std;
#define N 200005
#define ll long long
vector<int>R[N],C[N];//每一行|列内的障碍
ll tot,n,m,k; int main(){
cin>>n>>m>>k;
for(int i=;i<=k;i++){
int r,c;scanf("%d%d",&r,&c);
R[r].push_back(c);
C[c].push_back(r);
} for(int i=;i<=n;i++){
sort(R[i].begin(),R[i].end());
R[i].erase(unique(R[i].begin(),R[i].end()),R[i].end());
} for(int i=;i<=m;i++){
sort(C[i].begin(),C[i].end());
C[i].erase(unique(C[i].begin(),C[i].end()),C[i].end());
} tot=;
int lx=-,ly=-,dir=,up=,down=n+,l=,r=m+,x=,y=,newx,newy;
while(){
if(dir==){//向右走
int pos=lower_bound(R[x].begin(),R[x].end(),y)-R[x].begin();
if(pos==R[x].size())
newy=r-;//下面无边界
else newy=min(r,R[x][pos])-;
tot+=max(,newy-y);
dir=;
up=x;
y=newy;
}
else if(dir==){//向下走
int pos=lower_bound(C[y].begin(),C[y].end(),x)-C[y].begin();
if(pos==C[y].size())
newx=down-;//下面无边界
else newx=min(down,C[y][pos])-;
tot+=max(,newx-x);
dir=;
r=y;
x=newx;
}
else if(dir==){//向左走
int pos=lower_bound(R[x].begin(),R[x].end(),y)-R[x].begin()-;
if(pos<)
newy=l+;
else newy=max(l,R[x][pos])+;
tot+=max(,y-newy);
dir=;
down=x;
y=newy;
}
else if(dir==){//向上走
int pos=lower_bound(C[y].begin(),C[y].end(),x)-C[y].begin()-;
if(pos<)
newx=up+;
else newx=max(up,C[y][pos])+;
tot+=max(,x-newx);
dir=;
l=y;
x=newx;
}
if(x==lx && y==ly)break;//一格都不走表示动不了了
lx=x;ly=y;
} // cout<<tot;
if(tot==n*m-k)puts("Yes");
else puts("No"); return ;
}

模拟+细节题——cf1236D的更多相关文章

  1. Codeforces Round #398 (Div. 2) A B C D 模拟 细节 dfs 贪心

    A. Snacktower time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  2. HDOJ 2317. Nasty Hacks 模拟水题

    Nasty Hacks Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tota ...

  3. Codeforces Round #392 (Div. 2)-758D. Ability To Convert(贪心,细节题)

    D. Ability To Convert time limit per test 1 second Cmemory limit per test 256 megabytes input standa ...

  4. 【线段树 细节题】bzoj1067: [SCOI2007]降雨量

    主要还是细节分析:线段树作为工具 Description 我们常常会说这样的话:“X年是自Y年以来降雨量最多的”.它的含义是X年的降雨量不超过Y年,且对于任意Y<Z<X,Z年的降雨量严格小 ...

  5. POJ 2014:Flow Layout 模拟水题

    Flow Layout Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 3091   Accepted: 2148 Descr ...

  6. 洛谷P3926 SAC E#1 - 一道不可做题 Jelly【模拟/细节】

    P3926 SAC E#1 - 一道不可做题 Jelly [链接]:https://www.luogu.org/problem/show?pid=3926 题目背景 SOL君(炉石主播)和SOL菌(完 ...

  7. 【2019.10.7 CCF-CSP-2019模拟赛 T2】绝对值(abs)(线段树细节题)

    找规律 设\(p_i=a_{i+1}-a_i\),则答案就是\(\sum_{i=1}^{n-1}p_i\). 考虑若将\(a_i\)加上\(x\)(边界情况特殊考虑),就相当于是将\(p_{i-1}\ ...

  8. zoj 3745 Salary Increasing(坑爹的细节题!)

    题目 注意题目中的,引用绝望的乐园中的进一步解释如下: 这是一道浙大月赛的题,一如既往的坑爹,好好一道水题,被搞成一道坑题!!! //注意:r(i) < l(i+1) !细节啊细节! #incl ...

  9. Vladik and Favorite Game CodeForces - 811D (思维+BFS+模拟+交互题)

    D. Vladik and Favorite Game time limit per test 2 seconds memory limit per test 256 megabytes input ...

随机推荐

  1. generate ascii table

    $ cat ascii.sh dec_count=0 while [ $dec_count -lt 256 ] do echo -e "\x$(echo "ibase=10;oba ...

  2. nginx安装教程(详细)

    所见即所得编辑器, editorhtml{cursor:text;*cursor:auto} img,input,textarea{cursor:default}.cke_editable{curso ...

  3. Spring 源码学习——Aop

    Spring 源码学习--Aop 什么是 AOP 以下是百度百科的解释:AOP 为 Aspect Oriented Programming 的缩写,意为:面向切面编程通过预编译的方式和运行期动态代理实 ...

  4. 转 Jmeter参数化--Post请求的Post body 参数化

    2018年01月22日 15:40:58 java2013liu 阅读数:2361收起 个人分类: Jemter   一.使用body data设置参数: 1,首先,使用Fiddler录制post请求 ...

  5. Eureka 系列(06)消息广播(下):TaskDispacher 之 Acceptor - Worker 模式

    Eureka 系列(06)消息广播(下):TaskDispacher 之 Acceptor - Worker 模式 [TOC] Spring Cloud 系列目录 - Eureka 篇 Eureka ...

  6. Lucence使用入门

    参考: https://blog.csdn.net/u014209975/article/details/50525624 https://www.cnblogs.com/hanyinglong/p/ ...

  7. markdown_TestOne

    这个是我写的一个markdown尝试 1.2 dafsdfeasdfaefasdfase afsdfasdfefasdfeadfasdfe

  8. 【DRP】採用dom4j完毕XML文件导入数据库

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/lantingxv_jing/article/details/37762523     xml文件在如 ...

  9. JSON 和 xml 浅读

    1. JSON数据格式 JSON 语法是 JavaScript 对象表示法语法的子集. 数据在名称/值对中:名称是字符串,使用双引号表示.值可以是:数字(整数或浮点数),字符串(在双引号中),数组(在 ...

  10. Raspberry Pi 开机启动QT程序

    https://blog.csdn.net/coekjin/article/details/52498212 https://blog.csdn.net/dubuzherui/article/deta ...