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 雷锋网(公众号:雷锋网)按:本文作者科技剪刀手,思岚科技技术顾问. 随 ...
随机推荐
- nginx-1.12.2编译安装指导
nginx-1.12.2编译安装 下载源码包 安装 安装后配置 下载源码包 下载地址:http://nginx.org/en/download.html nginx-1.12.2:http://ngi ...
- JavaScript 面向对象编程(三):非构造函数对象的继承
JavaScript 面向对象编程(三):非构造函数对象的继承 一.什么是"非构造函数"的继承? 比如,现在有一个对象,叫做"中国人". var Chinese ...
- Ubuntu中在QT中配置OpenGL
之前搞实验室项目,博客有些天没有更新.现在学习需要,开始搞OpenGL+Ubuntu+QT. 搞了整整一天,由于是首次使用ubuntu,所以这ubuntu下配置qt和Opengl环境时走了很多的弯路, ...
- POJ-1159 Palindrome---变成回文串的最小代价
题目链接: https://cn.vjudge.net/problem/POJ-1159 题目大意: 题意很明确,给你一个字符串,可在任意位置添加字符,最少再添加几个字符,可以使这个字符串成为回文字符 ...
- web的攻击技术
简单的http协议本身并不存在安全性问题,因此技术本身几乎不会成为攻击的对象,应用http协议的服务器和客户端,以及运行在服务器端web应用等资源才是攻击目标,那么怎么攻击,来源于哪里呢 web应用攻 ...
- 【转】Activity生命周期详解
三个循环 提供两个关于Activity的生命周期模型图示帮助理解: 图1 图2 从图2所示的Activity生命周期 ...
- CUDA数组分配
原问链接 概述:数组分配可以通过cudaMallocArray()和cudaMalloc3DArray() 1.cudaMallocArray() cudaError_t cudaMallocArra ...
- Erwin 简单使用
1. 物理设计:汉译英过程 ① Logical 中操作:Tools-Names-Edit Naming Standards…-Glossary选项import,导入内容为编辑好的CSV文件(只包含中文 ...
- ssh框架复习
1.Hibernate中实体类的创建规则是什么? 2.hibernate中实体类的三种状态? 三种状态: 1. new 出来一个新对象 TakeTime takeTime = new TakeTime ...
- webpack4基本配置
1.npm init 生成package.json文件 2.npm install webpack webpack-cil --save-dev 安装webpack和webpack-cli ...