程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> POJ 1474 多邊形的核(半平面交)

POJ 1474 多邊形的核(半平面交)

編輯:C++入門知識

Video Surveillance Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 3145   Accepted: 1391

Description

A friend of yours has taken the job of security officer at the Star-Buy Company, a famous depart- ment store. One of his tasks is to install a video surveillance system to guarantee the security of the customers (and the security of the merchandise of course) on all of the store's countless floors. As the company has only a limited budget, there will be only one camera on every floor. But these cameras may turn around to look in every direction.

The first problem is to choose where to install the camera for every floor. The only requirement is that every part of the room must be visible from there. In the following figure the left floor can be completely surveyed from the position indicated by a dot, while for the right floor, there is no such position, the given position failing to see the lower left part of the floor.
\

Before trying to install the cameras, your friend first wants to know whether there is indeed a suitable position for them. He therefore asks you to write a program that, given a ground plan, de- termines whether there is a position from which the whole floor is visible. All floor ground plans form rectangular polygons, whose edges do not intersect each other and touch each other only at the corners.

Input

The input contains several floor descriptions. Every description starts with the number n of vertices that bound the floor (4 <= n <= 100). The next n lines contain two integers each, the x and y coordinates for the n vertices, given in clockwise order. All vertices will be distinct and at corners of the polygon. Thus the edges alternate between horizontal and vertical.

A zero value for n indicates the end of the input.

Output

For every test case first output a line with the number of the floor, as shown in the sample output. Then print a line stating "Surveillance is possible." if there exists a position from which the entire floor can be observed, or print "Surveillance is impossible." if there is no such position.

Print a blank line after each test case.

Sample Input

4
0 0
0 1
1 1
1 0
8
0 0
0 2
1 2
1 1
2 1
2 2
3 2
3 0
0

Sample Output

Floor #1
Surveillance is possible.

Floor #2
Surveillance is impossible.

 

給定一個多邊形,求多邊形的核。

將多邊形每一條邊延長,然後計算半平面交。

判斷點與直線關系由於模板少了一個等於號,導致當半平面退化成單點的時候判斷出錯,雖然浪費了一天的時間,但是改正了模板的一個錯誤,

還是值得的。

代碼:

 

/* ***********************************************
Author :_rabbit
Created Time :2014/5/4 15:03:55
File Name :20.cpp
************************************************ */
#pragma comment(linker, "/STACK:102400000,102400000")
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include
using namespace std;
#define INF 10000000
#define eps 1e-8
#define pi acos(-1.0)
typedef long long ll;
int dcmp(double x){
	if(fabs(x)0?1:-1;
}
struct Point{
	double x,y;
	Point(double _x=0,double _y=0){
		x=_x;y=_y;
	}
};
Point operator + (const Point &a,const Point &b){
	return Point(a.x+b.x,a.y+b.y);
}
Point operator - (const Point &a,const Point &b){
	return Point(a.x-b.x,a.y-b.y);
}
Point operator * (const Point &a,const double &p){
	return Point(a.x*p,a.y*p);
}
Point operator / (const Point &a,const double &p){
	return Point(a.x/p,a.y/p);
}
bool operator < (const Point &a,const Point &b){
	return a.x=0;
}
Point GetLineIntersection(Point p,Point v,Point q,Point w){
	Point u=p-q;
	double t=Cross(w,u)/Cross(v,w);
	return p+v*t;
}
Point GetLineIntersection(Line a,Line b){
	return GetLineIntersection(a.p,a.v,b.p,b.v);
}
vector HPI(vector L){
	int n=L.size();
	sort(L.begin(),L.end());//將所有半平面按照極角排序。
	/*for(int i=0;i p(n);
	vector q(n);
	vector ans;
	q[first=last=0]=L[0];
	for(int i=1;i p){
	int n=p.size();
	double ans=0;
	for(int i=1;i L;
		 Line s;
		 a=Point(-INF,-INF);b=Point(INF,-INF);s=Line(a,b-a);L.push_back(s);
		 a=Point(INF,-INF);b=Point(INF,INF);s=Line(a,b-a);L.push_back(s);
		 a=Point(INF,INF);b=Point(-INF,INF);s=Line(a,b-a);L.push_back(s);
		 a=Point(-INF,INF);b=Point(-INF,-INF);s=Line(a,b-a);L.push_back(s);
		 for(int i=0;i ans=HPI(L);
         if (cc) cout << endl;cout << "Floor #" << ++cc << endl;
          if (!ans.size()) cout << "Surveillance is impossible.\n";
              else cout << "Surveillance is possible.\n";
		 
	 }
     return 0;
}



 

 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved