模拟+细节题——cf1236D
思路好想,细节多的令人发指。。
/*
反着判断:走完每个点=走过的路程=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的更多相关文章
- 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 ...
- HDOJ 2317. Nasty Hacks 模拟水题
Nasty Hacks Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tota ...
- 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 ...
- 【线段树 细节题】bzoj1067: [SCOI2007]降雨量
主要还是细节分析:线段树作为工具 Description 我们常常会说这样的话:“X年是自Y年以来降雨量最多的”.它的含义是X年的降雨量不超过Y年,且对于任意Y<Z<X,Z年的降雨量严格小 ...
- POJ 2014:Flow Layout 模拟水题
Flow Layout Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 3091 Accepted: 2148 Descr ...
- 洛谷P3926 SAC E#1 - 一道不可做题 Jelly【模拟/细节】
P3926 SAC E#1 - 一道不可做题 Jelly [链接]:https://www.luogu.org/problem/show?pid=3926 题目背景 SOL君(炉石主播)和SOL菌(完 ...
- 【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}\ ...
- zoj 3745 Salary Increasing(坑爹的细节题!)
题目 注意题目中的,引用绝望的乐园中的进一步解释如下: 这是一道浙大月赛的题,一如既往的坑爹,好好一道水题,被搞成一道坑题!!! //注意:r(i) < l(i+1) !细节啊细节! #incl ...
- 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 ...
随机推荐
- Steup factory 面板介绍
2 安装软件信息 注册码 过期时间等一些设置 3 4 5
- v-bin:href 绑定链接
<div id="app06"> <a v-bind:href="URL">我是百度</a> </div> 调用 ...
- loadRunner之接口测试
接口测试需求: 1.脚本支持循环测试,并且每次测试的请求报文不一样(字段stbId每次请求不一样) 2.输出每次测试的请求报文和响应报文 3.根据响应报文判断接口调用是否成功 4.输出最终测试结果:循 ...
- PHP opendir() 函数
打开一个目录,读取它的内容,然后关闭: <?php$dir = "/images/"; // Open a directory, and read its contentsi ...
- ShellListView
過濾ShellListView顯示的檔案 有關這方面的元件你可以在Win3.中找到相關元件 你可以使用四個元件搭配應該就可以你所需要的功能 DriveComboBox1.FilterComboBox1 ...
- teradata在虚拟机安装客户端sql Assistant
学习链接:https://www.w3cschool.cn/teradata/? 1.安装过程
- 运维 03 Linux之文档与目录结构
Linux之文档与目录结构 Linux文件系统结构 Linux目录结构的组织形式和Windows有很大的不同.首先Linux没有“盘(C盘.D盘.E盘)”的概念.已经建立文件系统的硬盘分区被挂载到 ...
- Web RTC录视频
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Java8环境设置
假设你已经安装在 C:Program Filesjavajdk 目录: 在“我的电脑”右键单击并选择“属性”. 在“高级”选项卡下单击“环境变量”按钮. 现在,改变“Path”变量,因此,它也包含了路 ...
- linux nohup python 后台运行无输出问题
参考:https://blog.csdn.net/zj360202/article/details/78894512 nohup python test.py & nohup python t ...