题目:http://codeforces.com/problemset/problem/1236/D
思路:机器人只能按照→↓←↑这个规律移动,所以在当前方向能够前进的最远处即为界限,到达最远处右转,并且下次在该方向无法再移动到更远的地方,因此按照→↓←↑模拟即可,每次移动更新界限 ,无法移动则结束(第一次无法移动可右转,n*m会爆int)
          障碍用set存,每次二分寻找能到达最远的地方,并与界限比较

  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define pb push_back
  6. #define fi first
  7. #define se second
  8. #define mem(i,j) memset(i,j,sizeof(i))
  9.  
  10. typedef long long ll;
  11. typedef pair<int,int>pii;
  12.  
  13. ;
  14.  
  15. ll n,m;
  16. int k;
  17. int a,b;
  18. set<int>x[maxn],y[maxn];
  19.  
  20. int main()
  21. {
  22. scanf("%I64d%I64d%d",&n,&m,&k);
  23. ;i<=k;i++)
  24. {
  25. scanf("%d%d",&a,&b);
  26. x[a].insert(b);
  27. y[b].insert(a);
  28. }
  29. ;
  30. ,yy=;
  31. ll cnt=;
  32. int t;
  33. ,maxx=n,miny=,maxy=m;
  34. )
  35. {
  36. )
  37. {
  38. t=yy;
  39. auto it=x[xx].lower_bound(yy);
  40. if(it==x[xx].end()) yy=m;
  41. ;
  42. if(yy>maxy) yy=maxy;
  43. maxy=yy-;
  44. &&xx!=&&yy!=) break;
  45. cnt+=yy-t;
  46. }
  47. )
  48. {
  49. t=xx;
  50. auto it=y[yy].lower_bound(xx);
  51. if(it==y[yy].end()) xx=n;
  52. ;
  53. if(xx>maxx) xx=maxx;
  54. maxx=xx-;
  55. ) break;
  56. cnt+=xx-t;
  57. }
  58. )
  59. {
  60. t=yy;
  61. auto it=x[xx].lower_bound(yy);
  62. ;
  63. ;
  64. if(yy<miny) yy=miny;
  65. miny=yy+;
  66. ) break;
  67. cnt+=t-yy;
  68. }
  69. )
  70. {
  71. t=xx;
  72. auto it=y[yy].lower_bound(xx);
  73. ;
  74. ;
  75. if(xx<minx) xx=minx;
  76. minx=xx+;
  77. ) break;
  78. cnt+=t-xx;
  79. }
  80. ;}
  81. turn=(turn+)%;
  82.  
  83. }
  84. printf("No\n");
  85. ;
  86. }

Codeforces Round #593 (Div. 2) D. Alice and the Doll的更多相关文章

  1. Codeforces Round #593 (Div. 2)

    传送门 A. Stones 签到. B. Alice and the List of Presents 单独考虑每个数的贡献即可. 答案为\((2^{m}-1)^n\). C. Labs 构造就类似于 ...

  2. Codeforces Round #201 (Div. 2) - C. Alice and Bob

    题目链接:http://codeforces.com/contest/347/problem/C 题意是给你一个数n,然后n个数,这些数互不相同.每次可以取两个数x和y,然后可以得到|x - y|这个 ...

  3. Codeforces Round #593 (Div. 2) C. Labs A. Stones

    题目:https://codeforces.com/contest/1236/problem/A 思路:两种操作收益都是3 且都会消耗b 操作2对b消耗较小 则可优先选择操作2 再进行操作1 即可得到 ...

  4. Codeforces Round #593 (Div. 2) C. Labs

    题目:https://codeforces.com/contest/1236/problem/C 思路:将 n ^ 2 个 lab 平分为 n 个 group group A 和 B 组成的 有序对 ...

  5. Codeforces Round #593 (Div. 2)D(螺旋形模拟)

    #define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;vector<int>po[100 ...

  6. Codeforces Round #557 (Div. 1) 简要题解

    Codeforces Round #557 (Div. 1) 简要题解 codeforces A. Hide and Seek 枚举起始位置\(a\),如果\(a\)未在序列中出现,则对答案有\(2\ ...

  7. 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) & ...

  8. 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 ...

  9. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

随机推荐

  1. 01vscode配置git

    一.准备工作 必须保证已安装git,相关安装git的教程很多,这里就不进行描述. 通过命令:git --version 查看git版本. 二.git config 配置 通过git config 配置 ...

  2. DOM事件练习 II

    select框联动效果 需求:当在textarea中输入内容,点击留言按钮,会添加到浏览器中,最新留言出现在最顶端. <!DOCTYPE html> <html lang=" ...

  3. 【AMAD】Stream-Framework -- 让你可以使用Cassandra和Redis构建新闻feed,活动流(activity stream)以及通知系统。

    动机 简介 个人评分 动机 你曾经是否想为你自己的网站构建Facebook,Github那种feed流. 简介 通过Stream-Framework1你可以做到: Github那种活动流 Twitte ...

  4. SpringBoot配置文件值植入

    <!‐‐导入配置文件处理器,配置文件进行绑定就会有提示‐‐> <dependency> <groupId>org.springframework.boot</ ...

  5. 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 ...

  6. php 如何生成path及其日常维护

    php 如何生成path及其日常维护 path字段重要性不言而喻,在查询的时候,如果只用pid,查询效率会很低,增加path,查询效率大大提高,最起码不用递归查库了,重点是维护推荐关系的时候要维护pa ...

  7. 自动生成ID

    public class IdUtil { /** * * @return 返回时间id,类似于20191217195622 */ public static String timeId(){ Dat ...

  8. Python验证码登录(Tesseract安装配置)

    1.安装py库:pytesseract,PIL pip install pytesseract pip install PILLOW 如果安装时,出现权限不足: pip install --user ...

  9. 【原创】大叔经验分享(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 ...

  10. wpf ActualWidth为0解决方法

    LocalNewsControl() { var descriptor = DependencyPropertyDescriptor.FromProperty(ActualWidthProperty, ...