模拟+细节题——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 ...
随机推荐
- 【leetcode】942. DI String Match
题目如下: Given a string S that only contains "I" (increase) or "D" (decrease), let ...
- 【纪中集训】2019.08.10【NOIP提高组】模拟 A 组TJ
T1 Description Solution 有待填坑-- T2 Description 给定一个\(h(≤10)\)层.\(n(≤10)\)行.\(m(≤10)\)列的由泥土组成的立方体,挖开\( ...
- Mysql查看编码方式
查看数据库的字符集 show variables like 'character\_set\_%'; 输出: +--------------------------+--------+ | Varia ...
- MTD系统架构和yaffs2使用、Nandflash驱动设计
一.MTD系统架构 1.MTD设备体验 FLASH在嵌入式系统中是必不可少的,它是bootloader.linux内核和文件系统的最佳载体. 在Linux内核中引入了MTD子系统为NORFLASH和N ...
- Selenium webdriver 安装(一)
6年的.NET开发,干过小项目,做过研发,任何架构.设计模式.各种文档齐全.技术大牛,给我最深的体会是都不如用户最后的轻轻一点,一下毁所有.这个时候我突然想起了一首歌<都选C>哈哈.如何防 ...
- KEIL Code RO-data RW-data ZI-data 【转】
来自:http://jinyong314.blog.163.com/blog/static/30165742201052225415901/ 字节 8位半字 16位字 32位 Code, RO-d ...
- 自定义jQuery Mobile工具栏按钮
自定义jQuery Mobile工具栏按钮 1.实现效果
- (9)C++ 对象和类
一.类 1.访问控制 class student { int age;//默认私有控制 public: string name; double weight; }; 2.成员函数 定义成员函数时,使用 ...
- PAT甲级——A1153 DecodeRegistrationCardofPAT【25】
A registration card number of PAT consists of 4 parts: the 1st letter represents the test level, nam ...
- Selenium3 + Python3自动化测试系列十二——窗口截图与关闭浏览器
窗口截图 自动化用例是由程序去执行的,因此有时候打印的错误信息并不十分明确.如果在脚本执行出错的时候能对当前窗口截图保存,那么通过图片就可以非常直观地看出出错的原因.WebDriver提供了截图函数g ...