POJ 1066 Treasure Hunt(线段相交判断)
2017-06-28 21:41
344 查看
Treasure Hunt
Description
Archeologists from the Antiquities and Curios Museum (ACM) have flown to Egypt to examine the great pyramid of Key-Ops. Using state-of-the-art technology they are able to determine that the lower floor of the pyramid is constructed from a series of straightline
walls, which intersect to form numerous enclosed chambers. Currently, no doors exist to allow access to any chamber. This state-of-the-art technology has also pinpointed the location of the treasure room. What these dedicated (and greedy) archeologists want
to do is blast doors through the walls to get to the treasure room. However, to minimize the damage to the artwork in the intervening chambers (and stay under their government grant for dynamite) they want to blast through the minimum number of doors. For
structural integrity purposes, doors should only be blasted at the midpoint of the wall of the room being entered. You are to write a program which determines this minimum number of doors.
An example is shown below:
Input
The input will consist of one case. The first line will be an integer n (0 <= n <= 30) specifying number of interior walls, followed by n lines containing integer endpoints of each wall x1 y1 x2 y2 . The 4 enclosing walls of the pyramid have fixed endpoints
at (0,0); (0,100); (100,100) and (100,0) and are not included in the list of walls. The interior walls always span from one exterior wall to another exterior wall and are arranged such that no more than two walls intersect at any point. You may assume that
no two given walls coincide. After the listing of the interior walls there will be one final line containing the floating point coordinates of the treasure in the treasure room (guaranteed not to lie on a wall).
Output
Print a single line listing the minimum number of doors which need to be created, in the format shown below.
Sample Input
Sample Output
题意:穿墙中点出来,最少要穿几道墙
思路:枚举起点终点,求跟多少直线相交
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 7040 | Accepted: 2907 |
Archeologists from the Antiquities and Curios Museum (ACM) have flown to Egypt to examine the great pyramid of Key-Ops. Using state-of-the-art technology they are able to determine that the lower floor of the pyramid is constructed from a series of straightline
walls, which intersect to form numerous enclosed chambers. Currently, no doors exist to allow access to any chamber. This state-of-the-art technology has also pinpointed the location of the treasure room. What these dedicated (and greedy) archeologists want
to do is blast doors through the walls to get to the treasure room. However, to minimize the damage to the artwork in the intervening chambers (and stay under their government grant for dynamite) they want to blast through the minimum number of doors. For
structural integrity purposes, doors should only be blasted at the midpoint of the wall of the room being entered. You are to write a program which determines this minimum number of doors.
An example is shown below:
Input
The input will consist of one case. The first line will be an integer n (0 <= n <= 30) specifying number of interior walls, followed by n lines containing integer endpoints of each wall x1 y1 x2 y2 . The 4 enclosing walls of the pyramid have fixed endpoints
at (0,0); (0,100); (100,100) and (100,0) and are not included in the list of walls. The interior walls always span from one exterior wall to another exterior wall and are arranged such that no more than two walls intersect at any point. You may assume that
no two given walls coincide. After the listing of the interior walls there will be one final line containing the floating point coordinates of the treasure in the treasure room (guaranteed not to lie on a wall).
Output
Print a single line listing the minimum number of doors which need to be created, in the format shown below.
Sample Input
7 20 0 37 100 40 0 76 100 85 0 0 75 100 90 0 90 0 71 100 61 0 14 100 38 100 47 47 100 54.5 55.4
Sample Output
Number of doors = 2
题意:穿墙中点出来,最少要穿几道墙
思路:枚举起点终点,求跟多少直线相交
#include<iostream> #include<cstdio> #include<cstring> #include<string> #include<cmath> #include<queue> #include<stack> #include<vector> #include<cstring> #include<string> #include<algorithm> using namespace std; #define ll long long #define ms(a,b)memset(a,b,sizeof(a)) #define eps 1e-10 #define inf 1e8 int n,m,cntl,cntp; int Map[500][500]; double add(double a,double b) { if(abs(a+b)<eps*(abs(a)+abs(b))) return 0; return a+b; } struct P { double x,y; P(){} P(double x,double y): x(x),y(y){} P operator + (P p) { return P(add(x,p.x),add(y,p.y)); } P operator - (P p) { return P(add(x,-p.x),add(y,-p.y)); } P operator *(double d) { return P(x*d,y*d); } double dot (P p) { return add(x*p.x,y*p.y); } double det(P p) { return add(x*p.y,-y*p.x); } }p[35],q[35],inter[500]; bool on_seg(P p1,P p2,P q) { return (p1-q).det(p2-q)==0&&(p1-q).dot(p2-q)<0; } bool bianjieon_seg(P p1,P p2,P q) { return (p1-q).det(p2-q)==0&&(p1-q).dot(p2-q)<=0; } P intersection(P p1,P p2,P q1,P q2) { return p1+(p2-p1)*((q2-q1).det(q1-p1)/(q2-q1).det(p2-p1)); } bool xiangjiao(P p1,P p2,P p3,P p4) { if((p1-p2).det(p3-p4)==0) { return false; } P r=intersection(p1,p2,p3,p4); if(on_seg(p1,p2,r)&&on_seg(p3,p4,r)) return true; return false; } bool bianjiexiangjiao(P p1,P p2,P p3,P p4) { if((p1-p2).det(p3-p4)==0) { return false; } P r=intersection(p1,p2,p3,p4); if(bianjieon_seg(p1,p2,r)&&bianjieon_seg(p3,p4,r)) return true; return false; } int main() { while(~scanf("%d",&n)) { int cnt=0; for(int i=0;i<n;i++) scanf("%lf%lf%lf%lf",&p[i].x,&p[i].y,&q[i].x,&q[i].y); p .x=0;p .y=0;q .x=0;q .y=100; p[n+1].x=0;p[n+1].y=100;q[n+1].x=100;q[n+1].y=100; p[n+2].x=100;p[n+2].y=100;q[n+2].x=100;q[n+2].y=0; p[n+3].x=100;p[n+3].y=0;q[n+3].x=0;q[n+3].y=0; double xx,yy; scanf("%lf%lf",&xx,&yy); P st=P(xx,yy); for(int i=0;i<=n+3;i++) for(int j=i+1;j<=n+3;j++) { if(bianjiexiangjiao(p[i],q[i],p[j],q[j])) { if(i>=n||j>=n) inter[cnt++]=intersection(p[i],q[i],p[j],q[j]); } } int ans=999999; for(int i=0;i<cnt;i++) { int tmp=0; for(int j=0;j<n;j++) { if(xiangjiao(st,inter[i],p[j],q[j])) tmp++; } ans=min(tmp,ans); } 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(线段相交判断)
- Treasure Hunt - POJ 1066(线段相交判断)
- POJ 1066 Treasure Hunt(线段相交判断)
- 1066 Treasure Hunt (判断线段相交)
- POJ 1066 Treasure Hunt --几何,线段相交
- POJ 1066 Treasure Hunt (线段相交)
- POJ 1066 Treasure Hunt(线段相交&&转换)
- Poj 1066 Treasure Hunt && Nyoj 83 迷宫寻宝(二)判断线段相交
- POJ 1066 Treasure Hunt(浮点判断线段交点)
- 简单几何(线段相交) POJ 1066 Treasure Hunt
- POJ 1066 Treasure Hunt [线段相交]【计算几何】