POJ 1066 Treasure Hunt 线段交
来源:互联网 发布:php魔方加密在线解密 编辑:程序博客网 时间:2024/05/16 04:47
要到达目标点。
必然会经过一系列的线段
在这些线段上,在哪里开门都是一样的。
所以只需枚举边上的点到目标的点连接的线段中间交多少线段,求最小即可
#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <algorithm>#include <cstdlib>#include <cmath>#include <map>#include <sstream>#include <queue>#include <vector>#define MAXN 100005#define MAXM 211111#define eps 1e-8#define INF 500000001using namespace std;inline int dblcmp(double d){ if(fabs(d) < eps) return 0; return d > eps ? 1 : -1;}struct point{ double x, y; point(){} point(double _x, double _y): x(_x), y(_y) {} void input() { scanf("%lf%lf", &x, &y); } bool operator ==(point a)const { return dblcmp(a.x - x) == 0 && dblcmp(a.y - y) == 0; } point sub(point p) { return point(x - p.x, y - p.y); } double dot(point p) { return x * p.x + y * p.y; } double det(point p) { return x * p.y - y * p.x; } double distance(point p) { return hypot(x - p.x, y - p.y); }}p[111], des;struct line{ point a, b; line(){} line(point _a, point _b){ a = _a; b = _b;} void input() { a.input(); b.input(); } int segcrossseg(line v) { int d1 = dblcmp(b.sub(a).det(v.a.sub(a))); int d2 = dblcmp(b.sub(a).det(v.b.sub(a))); int d3 = dblcmp(v.b.sub(v.a).det(a.sub(v.a))); int d4 = dblcmp(v.b.sub(v.a).det(b.sub(v.a))); if ((d1 ^ d2) == -2 && (d3 ^ d4) == -2)return 2; return (d1 == 0 && dblcmp(v.a.sub(a).dot(v.a.sub(b))) <= 0|| d2 == 0 && dblcmp(v.b.sub(a).dot(v.b.sub(b))) <= 0|| d3 == 0 && dblcmp(a.sub(v.a).dot(a.sub(v.b))) <= 0|| d4 == 0 && dblcmp(b.sub(v.a).dot(b.sub(v.b))) <= 0); }}seg[111];int n, m, t;int main(){ p[n++] = point(0, 0); p[n++] = point(0, 100); p[n++] = point(100, 0); p[n++] = point(100, 100); scanf("%d", &t); for(int i = 0; i < t; i++) { seg[i].input(); p[n++] = seg[i].a; p[n++] = seg[i].b; } seg[t++] = line(p[0], p[1]); seg[t++] = line(p[0], p[2]); seg[t++] = line(p[1], p[3]); seg[t++] = line(p[2], p[3]); des.input(); int ans = INF; for(int i = 0; i < n; i++) { line tmp = line(p[i], des); int cnt = 0; for(int j = 0; j < t; j++) { if(tmp.segcrossseg(seg[j])) cnt++; } if(cnt < ans) ans = cnt; } printf("Number of doors = %d\n", ans - 1); return 0;}
- POJ 1066 Treasure Hunt 线段交
- poj 1066 Treasure Hunt (线段交)
- POJ 1066 Treasure Hunt (线段相交)
- poj 1066 Treasure Hunt(判断线段相交)
- POJ 1066 Treasure Hunt --几何,线段相交
- POJ 1066 Treasure Hunt(线段相交判断)
- POJ 1066 Treasure Hunt(线段相交判断)
- POJ 1066 Treasure Hunt 【线段相交】
- poj 1066 Treasure Hunt
- POJ 1066 Treasure Hunt
- POJ 1066 Treasure Hunt
- POJ 1066 Treasure Hunt
- poj 1066 Treasure Hunt
- POJ 1066 Treasure Hunt
- poj 1066 Treasure Hunt
- POJ 1066 Treasure Hunt
- poj 1066 Treasure Hunt
- POJ 1066 Treasure Hunt
- 汇编实现冒泡排序
- A Simple Problem with Integers
- 网络扫描技术揭秘读书笔记2--常用的网络编程-TCP/IP协议编程
- ORA-16038错误--当前REDO不能归档解决-转载整理
- object-c学习1
- POJ 1066 Treasure Hunt 线段交
- google play 安装植物大战僵尸2 国际版的方法
- LinearLayout中android:layout_weight的作用
- RefBase
- 在oracle中使用自增字段
- POJ 1410 Intersection 线段交
- Swing图片处理工具类ImageHelper
- What is Amplifier
- 黑马程序员--方法参数传递的方式