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

/*
反着判断:走完每个点=走过的路程=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 ;
}

最新文章

  1. 有状态Bean和无状态Bean的定义
  2. Ubuntu搭建Ruby On Rail环境
  3. XIV Open Cup named after E.V. Pankratiev. GP of SPb
  4. Arcengine实现创建网络数据集札记(三)
  5. Mysql存储日期类型用int、timestamp还是datetime?
  6. String类中toCharArray()方法的用法
  7. 对C#泛型中的new()约束思考
  8. cocos2dx3.4 导出节点树到XML文件
  9. mysql 数据库连接池
  10. vue 相对其他热门 框架 优点 --- 待续
  11. pwnable.kr bof之write up
  12. Java学习不走弯路教程(7.Eclipse环境搭建)
  13. 最大熵与最大似然,以及KL距离。
  14. 文件操作 chardet使用
  15. topcoder srm 370 div1
  16. Lua和C++交互 学习记录之九:在Lua中以面向对象的方式使用C++注册的类
  17. ios 内存管理与property copy strong weak assign
  18. vs计算代码行数
  19. 【LOJ】#2587. 「APIO2018」铁人两项
  20. synchronized修饰普通方法,修饰静态方法,修饰代码块,修饰线程run方法 比较

热门文章

  1. python字符转化
  2. JVM 和JMM的区别
  3. http协议和file协议的区别
  4. 92、R语言分析案例
  5. 在使用 Eclisp 生成 实体(sql Server) 出现错误 :Unable to locate JAR/zip in file system as specified by the driver definition: sqljdbc.jar.
  6. 用processing生成屏保程序
  7. IO Processing
  8. Vue环境搭建及第一个helloWorld
  9. PAT甲级——A1148 WerewolfSimpleVersion【20】
  10. sql server 与 oracle的区别(转)