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 ...
随机推荐
- Ceph osd故障硬盘更换
正常状态: 故障状态: 实施更换步骤: (1)关闭ceph集群数据迁移: osd硬盘故障,状态变为down.在经过mod osd down out interval 设定的时间间隔后,ceph将其标记 ...
- 【MM系列】SAP S/4 HANA BP创建客户/供应商的一点想法
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[MM系列]SAP S/4 HANA BP创建客 ...
- 重学 html の meta 标签
参考链接: https://segmentfault.com/a/1190000019052062?utm_medium=hao.caibaojian.com&utm_source=hao.c ...
- 强化学习复习笔记 - DEEP
Outline 激活函数 使用逼近器的特点: 较少数量的参数表达复杂的函数 (计算复杂度) 对一个权重的调整可以影响到很多的点 (泛化能力) 多种特征表示和逼近器结构 (多样性) 激活函数 Sigmo ...
- 学习shell的第三天
编程原理:1.编程介绍 早期编程: 驱动 硬件默认是不能使用的: 不同的厂家硬件设备之间需要进行指令沟通,我们需要驱动程序来进行“翻译”: 更趋近与硬件开发的工程师,要学习“汇编语言”:而“汇 ...
- 第五周课程总结&试验报告三
第五周课程总结 一.第五周课程总结 1.this关键字 this可用于任何实例方法内指向当前对象,也可指向对其调用当前方法的对象,或者在需要当前类型对象引用时使用.当一个类的属性(成员变量)名与访问该 ...
- Java基础(十)
复习 静态方法与成员方法 //另一个类里的静态和成员方法 public class MyClass { //静态方法 public static void method2() { System.out ...
- 必备idea 插件plugins 提高编码效率
最近发现了几个非常好用 提高编码效率 的idea 插件 跟大家分享一下 因为idea自带的插件下载可能连接不上服务器而导致插件下载失败,所以这里推荐使用引入外部插件的方式 插件包也给你们准备好了( ...
- java中的12种锁
java中很多地方会涉及到锁,比如java代码并发场景,DB中的并发场景,分布式中的锁....你知道几种呢?下面来看看常见的11种锁 1. 乐观锁/悲观锁 这两个概念是人们对java中各种锁总结提出的 ...
- JS获取url中的指定参数
function GetRequest() { var url = location.search; //获取url中"?"符后的字串 var theRequest = new O ...