题目: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的更多相关文章

  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. 1004: [递归]母牛的故事(python):(本地测试正确;但提交不对!!??)求教

    时间限制: 1Sec 内存限制: 128MB 提交: 28438 解决: 8320 题目描述 有一头母牛,它每年年初生一头小母牛.每头小母牛从第四个年头开始,每年年初也生一头小母牛.请编程实现在第n年 ...

  2. git 参考手册-简明指南

    很久没发文了,来头条以后更忙了,也没精力去分享一些有营养的内容了.这次分享的 git 的方方面面,基本来自于我的笔记.git 这东西算是为数不多每天都要用的东西了,但是我觉得也不至于从头至尾去了解他的 ...

  3. __setattr__,__getattr__,__delattr__

    class Foo: x = 1 def __init__(self,y): self.y = y def __getattr__(self,item): print("---->fr ...

  4. 【并行计算-CUDA开发】Windows下opencl环境配置

    首先声明我这篇主要是根据下面网站的介绍, 加以修改和详细描述,一步一步在我自己的电脑上实现的, http://www.cmnsoft.com/wordpress/?tag=opencl&pag ...

  5. 修改iframe内元素的样式

      $('iframe').load(function () { var x = document.getElementsByTagName('iframe')[0]; var y = (x.cont ...

  6. JS延迟加载的几种方式

    参考链接:https://blog.csdn.net/meijory/article/details/76389762

  7. 菜鸟系列k8s——k8s集群部署(2)

    k8s集群部署 1. 角色分配 角色 IP 安装组件 k8s-master 10.0.0.170 kube-apiserver,kube-controller-manager,kube-schedul ...

  8. (转载)Nim博弈论

    最近补上次参加2019西安邀请赛的题,其中的E题出现了Nim博弈论,今天打算好好看看Nim博弈论,在网上看到这篇总结得超级好的博客,就转载了过来. 转载:https://www.cnblogs.com ...

  9. mysql事件(event)

    [小结]简单案例 SET GLOBAL event_scheduler=1delimiter $$ create definer = current_user event `test`.`event_ ...

  10. Python学习【day04】- Python基础(集合、函数)

    集合 #!/usr/bin/env python # -*- coding:utf8 -*- # set集合 只可放不可变的数据类型,本身是可变数据类型,无序 # s = {1,2,3,[1,2,3] ...