Hihocoder 1275 扫地机器人 计算几何
题意:
有一个房间的形状是多边形,而且每条边都平行于坐标轴,按顺时针给出多边形的顶点坐标
还有一个正方形的扫地机器人,机器人只可以上下左右移动,不可以旋转
问机器人移动的区域能不能覆盖整个房间
分析:
#include <cstdio>
#include <cmath>
#include <algorithm>
using std::abs;
using std::swap;
const int maxn = 1010;
struct Point
{
int x, y;
Point(int x = 0, int y = 0): x(x), y(y) {}
void read() { scanf("%d%d", &x, &y); }
Point operator - (const Point& t) const {
return Point(x - t.x, y - t.y);
}
};
int n, m;
Point p[maxn], dir[maxn]; //dir是边的单位方向向量
int angle[maxn]; //用叉积判断内外角,angle为正是外角,为负是内角
int sign(int x) { if(!x) return 0; return x > 0 ? 1 : -1; }
Point Normalize(Point A) {
return Point(sign(A.x), sign(A.y));
}
int Cross(Point A, Point B) { return A.x * B.y - A.y * B.x; }
int Length(Point A) { if(A.x) return abs(A.x); return abs(A.y); }
int left, right, top, bottom; //机器人沿某条边扫过的矩形
//判断扫描区域是否与房间的某条边相交
bool intersect() {
for(int i = 1; i <= n; i++) {
if(p[i].x <= left && p[i+1].x <= left) continue;
if(p[i].x >= right && p[i+1].x >= right) continue;
if(p[i].y <= bottom && p[i+1].y <= bottom) continue;
if(p[i].y >= top && p[i+1].y >= top) continue;
return true;
}
return false;
}
int main()
{
int q; scanf("%d", &q);
while(q--) {
scanf("%d%d", &n, &m);
for(int i = 1; i <= n; i++) p[i].read();
p[n + 1] = p[1];
for(int i = 1; i <= n; i++) dir[i] = Normalize(p[i+1]-p[i]);
dir[0] = dir[n];
for(int i = 1; i <= n; i++) angle[i] = Cross(dir[i - 1], dir[i]);
angle[n + 1] = angle[1];
bool ok = true;
for(int i = 1; i <= n; i++) {
if(angle[i] < 0 && angle[i+1] < 0 && Length(p[i+1]-p[i]) < m) {
ok = false; break;
}
if(dir[i].x) {
int delta = m * dir[i].x;
left = p[i].x; right = p[i+1].x;
if(angle[i] > 0) left -= delta;
if(angle[i+1] > 0) right += delta;
top = p[i].y; bottom = top - delta;
} else {
int delta = m * dir[i].y;
top = p[i].y; bottom = p[i+1].y;
if(angle[i] > 0) top -= delta;
if(angle[i+1] > 0) bottom += delta;
left = p[i].x; right = left + delta;
}
if(left > right) swap(left, right);
if(bottom > top) swap(bottom, top);
if(intersect()) { ok = false; break; }
}
printf("%s\n", ok ? "Yes" : "No");
}
return 0;
}
Hihocoder 1275 扫地机器人 计算几何的更多相关文章
- [LeetCode] Robot Room Cleaner 扫地机器人
Given a robot cleaner in a room modeled as a grid. Each cell in the grid can be empty or blocked. Th ...
- 【BZOJ5318】[JSOI2018]扫地机器人(动态规划)
[BZOJ5318][JSOI2018]扫地机器人(动态规划) 题面 BZOJ 洛谷 题解 神仙题.不会.... 先考虑如果一个点走向了其下方的点,那么其右侧的点因为要被访问到,所以必定只能从其右上方 ...
- Java实现第十届蓝桥杯JavaC组第十题(试题J)扫地机器人
扫地机器人 时间限制: 1.0s 内存限制: 512.0MB 本题总分:25 分 [问题描述] 小明公司的办公区有一条长长的走廊,由 N 个方格区域组成,如下图所 示. 走廊内部署了 K 台扫地机器人 ...
- [LeetCode] 489. Robot Room Cleaner 扫地机器人
Given a robot cleaner in a room modeled as a grid. Each cell in the grid can be empty or blocked. Th ...
- LGP4588[JSOI2018]扫地机器人
题解 需要先说明一点东西: 1 同一副对角线方向相同,共有$gcd(n,m)$条不同的副对角线,机器人的行为是一个$gcd(n,m)$的循环:: 如果左上方是$(1,1)$,容易看出所有的路径是从左或 ...
- 489. Robot Room Cleaner扫地机器人
[抄题]: Given a robot cleaner in a room modeled as a grid. Each cell in the grid can be empty or block ...
- hihocoder 1582 : Territorial Dispute (计算几何)(2017 北京网络赛E)
题目链接 题意:给出n个点.用两种颜色来给每个点染色.问能否存在一种染色方式,使不同颜色的点不能被划分到一条直线的两侧. 题解:求个凸包(其实只考虑四个点就行.但因为有板子,所以感觉这样写更休闲一些. ...
- 除了ROS, 机器人定位导航还有其他方案吗?
利用ROS进行机器人开发,我想大多数企业是想借助ROS实现机器人的导航.定位与路径规划,它的出现大大降低了机器人领域的开发门槛,开发者无需向前人一样走众多弯路,掌握多种知识才能开始实现机器人设计的梦想 ...
- 除了ROS ,机器人自主定位导航还能怎么做?
博客转载自:https://www.leiphone.com/news/201609/10QD7yp7JFV9H9Ni.html 雷锋网(公众号:雷锋网)按:本文作者科技剪刀手,思岚科技技术顾问. 随 ...
随机推荐
- URL地址中中文乱码详解(javascript中encodeURI和decodeURI方法、java.net.URLDecoder.encode、java.net.URLDecoder.decode)
引言: 在Restful类的服务设计中,经常会碰到需要在URL地址中使用中文作为的参数的情况,这种情况下,一般都需要正确的设置和编码中文字符信息.乱码问题就此产生了,该如何解决呢?且听本文详细道来. ...
- sharepoint知识点总结
{ users.Add(value.User); } else { SPGroup group = web.Groups.GetByID(value.LookupId); groups.Add(gro ...
- dell Nx000系列交换机
dell n2048(P) dell n3048(P) dell n4064(F) P: PoE+ F: SFP+ Model GbE 10GbE(SFP+) 40GbE(QSFP+) Layer d ...
- 光标显示样式 css 中 cursor 属性使用
记录一下 cursor 的各种样式,方便自己查找.之前用到不常用的每次去 百度 或 Google 找不如自己记录下好找些. cursor光标类型 auto default none context-m ...
- 微信小程序又一爆炸功能上线-云开发
云开发介绍 开发者可以使用云开发开发微信小程序.小游戏,无需搭建服务器,即可使用云端能力. 云开发为开发者提供完整的云端支持,弱化后端和运维概念,无需搭建服务器,使用平台提供的 API 进行核心业务开 ...
- CAD出现向程序发送命令时出现问题提示解决方法分享
大家有没有遇到在使用cad打开图纸的时候提示向程序发送命令时出现错误的情况呢,如果你在使用cad的时候出现了这个提示,是由于软件的兼容性出现了问题,那么该怎么办呢,下面小编就给大家带来cad打开图纸提 ...
- Last_SQL_Errno: 1050
主库上create table,从库上存在. 报错信息如下所示: Last_SQL_Errno: 1050 Last_SQL_Error: ...
- 砍树,POJ(2665)
题目链接:http://poj.org/problem?id=2665 解题报告: 这里的区域没有重复,若有重复的话,模拟即可. #include <cstdio> #include &l ...
- PRmakefile文件
Ubuntu下的makefile: # /******************************************************************************* ...
- Git笔记(pull/push)
一.从远程服务器上获取分支 git pull <远程主机名> <远程分支>:<本地分支> 例如 git pull origin master:loacal_bran ...