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 雷锋网(公众号:雷锋网)按:本文作者科技剪刀手,思岚科技技术顾问. 随 ...
随机推荐
- u-boot分析(十)----堆栈设置|代码拷贝|完成BL1阶段
u-boot分析(十) 上篇博文我们按照210的启动流程,分析到了初始化nand flash,由于接下来的关闭ABB比较简单所以跳过,所以我们今天按照u-boot的启动流程继续进行分析. 今天我们会用 ...
- Struts2_HelloWorld1
打开 eclipse,新建 web 项目. 因为可能需要 jstl 表达式,所以添加 jstl需要的jar包. 下载链接:http://pan.baidu.com/s/1hr6mBI0 将jar拷贝至 ...
- 带你了解强大的Cadence家族,你可能只用到了它1/10的工具
[转载自 SI-list[中国]http://mp.weixin.qq.com/s/qsdfzQwIVjvwHXuCdvrPXA ] 本篇对2017年初版Cadence的全套所有EDA工具的技术特性特 ...
- megacli使用
查看raid类型 /opt/RAID/MegaCli64 -ShowSummary -a0 System Operating System: Linux version 2.6.32-220.el6. ...
- mysql : 修改数据库权限
解决步骤 第一步,点击用户 注意!!! 编辑权限,在我们设置权限之前,我们需要先重新加载才能生效, 如果不用编辑的话,直接按重新载入编辑,这个相当于保存. 中文意思(注意看那段话) 第二步 选择要处理 ...
- mysql在控制台里出现中文问号问题
由于重装了wampserver,之前遇到的问题统统会重新出现,那么今天遇到的是在mysql控制台中,在表里输入中文数据,却出现问号的问题: 那么这个就跟编码有关系了,那么,我们就去wampserver ...
- 非常全面的PHP header函数设置HTTP头的示例
突然看到这个,觉得很好,就拿过来了,如下: //定义编码 header( 'Content-Type:text/html;charset=utf-8 '); //Atom header('Conten ...
- [转载]Memcached缓存服务的简单安装
1.Linux下的安装方法 下载:wget http://memcached.org/latest tar -zxvf memcached-1.x.x.tar.gz cd memcached-1.x. ...
- SQL的注入式攻击方式和避免方法
SQL 注入是一种攻击方式,在这种攻击方式中,恶意代码被插入到字符串中,然后将该字符串传递到 SQL Server 的实例以进行分析和执行.任何构成 SQL 语句的过程都应进行注入漏洞检查,因为 SQ ...
- Linux MySQL单实例源码编译安装5.5.32
cmake软件 tar -zxvf cmake-2.8.8.tar.gz cd cmake-2.8.8 ./bootstrap make make install cd ../ 依赖包 yum i ...