Codeforces Round #593 (Div. 2) D. Alice and the Doll
题目:http://codeforces.com/problemset/problem/1236/D
思路:机器人只能按照→↓←↑这个规律移动,所以在当前方向能够前进的最远处即为界限,到达最远处右转,并且下次在该方向无法再移动到更远的地方,因此按照→↓←↑模拟即可,每次移动更新界限 ,无法移动则结束(第一次无法移动可右转,n*m会爆int)
障碍用set存,每次二分寻找能到达最远的地方,并与界限比较
- #include<bits/stdc++.h>
- using namespace std;
- #define pb push_back
- #define fi first
- #define se second
- #define mem(i,j) memset(i,j,sizeof(i))
- typedef long long ll;
- typedef pair<int,int>pii;
- ;
- ll n,m;
- int k;
- int a,b;
- set<int>x[maxn],y[maxn];
- int main()
- {
- scanf("%I64d%I64d%d",&n,&m,&k);
- ;i<=k;i++)
- {
- scanf("%d%d",&a,&b);
- x[a].insert(b);
- y[b].insert(a);
- }
- ;
- ,yy=;
- ll cnt=;
- int t;
- ,maxx=n,miny=,maxy=m;
- )
- {
- )
- {
- t=yy;
- auto it=x[xx].lower_bound(yy);
- if(it==x[xx].end()) yy=m;
- ;
- if(yy>maxy) yy=maxy;
- maxy=yy-;
- &&xx!=&&yy!=) break;
- cnt+=yy-t;
- }
- )
- {
- t=xx;
- auto it=y[yy].lower_bound(xx);
- if(it==y[yy].end()) xx=n;
- ;
- if(xx>maxx) xx=maxx;
- maxx=xx-;
- ) break;
- cnt+=xx-t;
- }
- )
- {
- t=yy;
- auto it=x[xx].lower_bound(yy);
- ;
- ;
- if(yy<miny) yy=miny;
- miny=yy+;
- ) break;
- cnt+=t-yy;
- }
- )
- {
- t=xx;
- auto it=y[yy].lower_bound(xx);
- ;
- ;
- if(xx<minx) xx=minx;
- minx=xx+;
- ) break;
- cnt+=t-xx;
- }
- ;}
- turn=(turn+)%;
- }
- printf("No\n");
- ;
- }
Codeforces Round #593 (Div. 2) D. Alice and the Doll的更多相关文章
- Codeforces Round #593 (Div. 2)
传送门 A. Stones 签到. B. Alice and the List of Presents 单独考虑每个数的贡献即可. 答案为\((2^{m}-1)^n\). C. Labs 构造就类似于 ...
- Codeforces Round #201 (Div. 2) - C. Alice and Bob
题目链接:http://codeforces.com/contest/347/problem/C 题意是给你一个数n,然后n个数,这些数互不相同.每次可以取两个数x和y,然后可以得到|x - y|这个 ...
- Codeforces Round #593 (Div. 2) C. Labs A. Stones
题目:https://codeforces.com/contest/1236/problem/A 思路:两种操作收益都是3 且都会消耗b 操作2对b消耗较小 则可优先选择操作2 再进行操作1 即可得到 ...
- Codeforces Round #593 (Div. 2) C. Labs
题目:https://codeforces.com/contest/1236/problem/C 思路:将 n ^ 2 个 lab 平分为 n 个 group group A 和 B 组成的 有序对 ...
- Codeforces Round #593 (Div. 2)D(螺旋形模拟)
#define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;vector<int>po[100 ...
- Codeforces Round #557 (Div. 1) 简要题解
Codeforces Round #557 (Div. 1) 简要题解 codeforces A. Hide and Seek 枚举起始位置\(a\),如果\(a\)未在序列中出现,则对答案有\(2\ ...
- Codeforces Round #721 (Div. 2)A. And Then There Were K(位运算,二进制) B1. Palindrome Game (easy version)(博弈论)
半个月没看cf 手生了很多(手动大哭) Problem - A - Codeforces 题意 给定数字n, 求出最大数字k, 使得 n & (n−1) & (n−2) & ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
随机推荐
- 01vscode配置git
一.准备工作 必须保证已安装git,相关安装git的教程很多,这里就不进行描述. 通过命令:git --version 查看git版本. 二.git config 配置 通过git config 配置 ...
- DOM事件练习 II
select框联动效果 需求:当在textarea中输入内容,点击留言按钮,会添加到浏览器中,最新留言出现在最顶端. <!DOCTYPE html> <html lang=" ...
- 【AMAD】Stream-Framework -- 让你可以使用Cassandra和Redis构建新闻feed,活动流(activity stream)以及通知系统。
动机 简介 个人评分 动机 你曾经是否想为你自己的网站构建Facebook,Github那种feed流. 简介 通过Stream-Framework1你可以做到: Github那种活动流 Twitte ...
- SpringBoot配置文件值植入
<!‐‐导入配置文件处理器,配置文件进行绑定就会有提示‐‐> <dependency> <groupId>org.springframework.boot</ ...
- PTA(Advanced Level)1046.Shortest Distance
The task is really simple: given N exits on a highway which forms a simple cycle, you are supposed t ...
- php 如何生成path及其日常维护
php 如何生成path及其日常维护 path字段重要性不言而喻,在查询的时候,如果只用pid,查询效率会很低,增加path,查询效率大大提高,最起码不用递归查库了,重点是维护推荐关系的时候要维护pa ...
- 自动生成ID
public class IdUtil { /** * * @return 返回时间id,类似于20191217195622 */ public static String timeId(){ Dat ...
- Python验证码登录(Tesseract安装配置)
1.安装py库:pytesseract,PIL pip install pytesseract pip install PILLOW 如果安装时,出现权限不足: pip install --user ...
- 【原创】大叔经验分享(55)spark连接kudu报错
spark-2.4.2kudu-1.7.0 开始尝试 1)自己手工将jar加到classpath spark-2.4.2-bin-hadoop2.6+kudu-spark2_2.11-1.7.0-cd ...
- wpf ActualWidth为0解决方法
LocalNewsControl() { var descriptor = DependencyPropertyDescriptor.FromProperty(ActualWidthProperty, ...