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 ...
随机推荐
- 外国前端收费模板wrapbootstrap
https://wrapbootstrap.com/ 新闻模板 http://wrapbootstrap.com/preview/WB037B6R2
- 【.NET】关于.NET前后台提示框的那点事
前言 关于提示框,或多或少都用到过,提示框常见方式两种:js原生alert() 和 div模拟弹层:下面以一个常见的需求业务场景来展现提示框的那点事: 正文内容 客户:需求方: 小白:实现方(全权负责 ...
- JAVA_day2_运算符
Java运算符 一.算术运算符 ++ 和 -- 既可以出现在操作数的左边,也可以出现在右边,但结果不同 1.++在左边,a先自增1再赋值给b int a=3 int b=++a 2.++在右边,先赋值 ...
- sqlalchemy一对多的关系
#encoding: utf-8 from sqlalchemy import create_engine,Column,Integer,String,Float,func,and_,or_,Text ...
- 安装Composer与PsySH
Windows安装Composer 需要开启 openssl 配置:打开 php 目录下的 php.ini,将 extension=php_openssl.dll 前面的分号去掉就可以了. https ...
- Python 入门 之 类的约束以及super()剖析
Python 入门 之 类的约束以及super()剖析 1.类的约束 第一版: class WechatPay: def pay(self): print("微信支付") clas ...
- shell脚本之nginx启动脚本、统计日志字段、for循环实战、跳板机
1.NGINX启动脚本 #!/bin/bash # chkconfig: 235 32 62 # description: nginx [ -f /etc/init.d/functions ] &am ...
- 剑指offer-数组中只出现一次的数字-数组-python
题目描述 一个整型数组里除了两个数字之外,其他的数字都出现了两次.请写程序找出这两个只出现一次的数字. # -*- coding:utf-8 -*- class Solution: # 返回[a, ...
- 为什么日本编程语言ruby没前途
ruby是日本的编程语言,不像日本生鱼片一样受人喜欢 日本 Ruby的性能不如.NET或Java 你又是对的!另外,Ruby比Erlang,Lua,C ++等慢,但你不使用Erlang或C ++? W ...
- Date对象中的方法
特殊说明:设置时间的方法,虽然W3C说明传参的范围,在开发过程中,传入的参数不在该范围也是可以的.例如: var t = new Date(), d = t.getDate(); //当天时间往前推2 ...