poj1066--Treasure Hunt(规范相交)
题目链接:点击打开链接
题目大意:一个正方形的墓葬内有n堵墙,每堵墙的两个顶点都在正方形的边界上,如今这些墙将墓葬切割成了非常多小空间,已知正方形内的一个点上存在宝藏,如今我们要在正方形的外面去得到宝藏,对于每一个小空间,我们能够炸开它的随意一条边的中点,如今给出每堵墙的两个节点的坐标和宝藏的坐标,问假设要得到宝藏,须要炸的墙数最少是多少。
枚举正方形边界上的点作为进入正方形的节点,由这个点向宝藏连出一条线段,这条线段和多少个墙相交,那么就须要炸坏多少个墙,找出一个最小的值。
原因,由于每堵墙的两个节点都在边界上,所以假设和墙相交,那么就一定要跨过这道墙,所以须要炸掉它。
一定要是规范相交,由于假设枚举的点假设是一堵墙的节点,那么这堵墙是不应该被计算的。
(应该是枚举出边界上的小空间的中点,为了省事,直接枚举全部的点。
)
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std ;
#define eps 1e-8
#define zero(x) (((x) > 0 ? (x) : (-x)) < eps)
struct Point {
double x, y;
};
struct Line {
Point a, b;
}l[35], len[4];
int n ;
double xmult(Point p1, Point p2, Point p) {
return (p1.x-p.x)*(p2.y-p.y) - (p2.x-p.x)*(p1.y-p.y);
}
double dmult(Point p1, Point p2, Point p) {
return (p1.x-p.x)*(p2.x-p.x) + (p1.y-p.y)*(p2.y-p.y);
}
double distance(Point p1, Point p2) {
return sqrt((p1.x-p2.x)*(p1.x-p2.x)
+ (p1.y-p2.y)*(p1.y-p2.y));
}
int opposite_side(Point p1,Point p2,Line l) {
return xmult(l.a, p1, l.b)*xmult(l.a, p2, l.b) < -eps;
}
int intersect_ex(Line u, Line v) {
return opposite_side(u.a, u.b, v)
&& opposite_side(v.a, v.b, u);
}
int solve(Line len) {
int i, num = 0;
for(i = 0; i < n; i++) {
if( intersect_ex(l[i],len) ) num++;
}
return num;
}
int main() {
int i , ans ;
while( scanf("%d", &n) != EOF ) {
ans = n ;
for(i = 0; i < n; i++) {
scanf("%lf %lf %lf %lf", &l[i].a.x, &l[i].a.y, &l[i].b.x, &l[i].b.y);
}
scanf("%lf %lf", &len[0].a.x, &len[0].a.y) ;
len[1] = len[2] = len[3] = len[0];
len[0].b.y = len[3].b.x = 100 ;
len[1].b.y = len[2].b.x = 0 ;
for(i = 0; i <= 100; i++) {
len[0].b.x = len[3].b.y = len[1].b.x = len[2].b.y = i ;
ans = min(ans, solve(len[0]));
ans = min(ans, solve(len[1]));
ans = min(ans, solve(len[2]));
ans = min(ans, solve(len[3]));
}
ans++ ;
printf("Number of doors = %d\n", ans) ;
}
return 0 ;
}
poj1066--Treasure Hunt(规范相交)的更多相关文章
- POJ 1066 Treasure Hunt(线段相交判断)
Treasure Hunt Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4797 Accepted: 1998 Des ...
- poj1066 Treasure Hunt【计算几何】
Treasure Hunt Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8192 Accepted: 3376 Des ...
- POJ 1066 Treasure Hunt(相交线段&&更改)
Treasure Hunt 大意:在一个矩形区域内.有n条线段,线段的端点是在矩形边上的,有一个特殊点,问从这个点到矩形边的最少经过的线段条数最少的书目,穿越仅仅能在中点穿越. 思路:须要巧妙的转换一 ...
- POJ1066 Treasure Hunt
嘟嘟嘟 题意看题中的图就行:问你从给定的点出发最少需要穿过几条线段才能从正方形中出去(边界也算). 因为\(n\)很小,可以考虑比较暴力的做法.枚举在边界中的哪一个点离开的.也就是枚举四周的点\((x ...
- poj 1066 Treasure Hunt 线段相交
题目链接 题目描述 一个正方形房间被分成若干个小室,宝藏在其中某一点.现可炸开任意一堵墙壁的中点位置.问至少要炸开多少堵墙才能从外面到达宝藏所在地. 思路 (很巧妙,没想到) 直接枚举墙壁与正方形外壁 ...
- POJ 1066 - Treasure Hunt - [枚举+判断线段相交]
题目链接:http://poj.org/problem?id=1066 Time Limit: 1000MS Memory Limit: 10000K Description Archeologist ...
- zoj Treasure Hunt IV
Treasure Hunt IV Time Limit: 2 Seconds Memory Limit: 65536 KB Alice is exploring the wonderland ...
- HDU 1558 Segment set (并查集+线段非规范相交)
题目链接 题意 : 如果两个线段相交就属于同一集合,查询某条线段所属集合有多少线段,输出. 思路 : 先判断与其他线段是否相交,然后合并. #include <cstdio> #inclu ...
- ZOJ3629 Treasure Hunt IV(找到规律,按公式)
Treasure Hunt IV Time Limit: 2 Seconds Memory Limit: 65536 KB Alice is exploring the wonderland ...
随机推荐
- Spring学习总结(10)——Spring JMS---三种消息监听器
消息监听器MessageListener 在spring整合JMS的应用中我们在定义消息监听器的时候一共可以定义三种类型的消息监听器,分别是MessageListener.SessionAwareMe ...
- 51 nod 1189 阶乘分数
题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1189 题目思路: 1/n! = 1/x +1/y ==> ...
- RHEL6安装调试过程中遇到的问题集
/*** **问题集 2014/6/9 20:55:52** **Autor: Weigong Xu ** ***/ 1. Linux中开启22port: 22port是ssh服务的.你仅仅要启动ss ...
- Android时间戳与字符串相互转换
import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public cl ...
- 00096_Properties类
1.Properties类介绍 (1)Properties 类表示了一个持久的属性集.Properties 可保存在流中或从流中加载.属性列表中每个键及其对应值都是一个字符串: (2)特点 Hasht ...
- 【CS Round #44 (Div. 2 only) D】Count Squares
[链接]点击打开链接 [题意] 给你一个0..n和0..m的区域. 你可以选定其中的4个点,然后组成一个正方形. 问你可以圈出多少个正方形. (正方形的边不一定和坐标轴平行) [题解] 首先,考虑只和 ...
- 彩票案例-frame,center和bounds属性
控件的属性: 二.frame.center和bounds属性 " 在iOS中,每一个控件都是继承于UIView的.都会有视图的属性存在,控制这个视图的位置就有Frame和Bounds两个属性 ...
- Android实践 -- 对apk进行系统签名
对apk进行系统签名 签名工具 网盘下载 ,需要Android系统的签名的文件 platform.x509.pem 和 platform.pk8 这个两个文件在Android源码中的 ./build/ ...
- [Angular2 Router] Redirects and Path Matching - Avoid Common Routing Pitfall
In this tutorial we are going to learn how we can can configure redirects in the angular 2 router co ...
- 辛星解读之php中的重点函数第一节之数组函数
这里我已经写好它的pdf版本号了,比本博客更加适合阅读.首先说一下它在百度网盘的下载地址把:百度网盘下载 ,假设左边连接跪了.能够在浏览器中输入:http://pan.baidu.com/s/1qW5 ...