您的位置:首页 > 其它

POJ 1474 Video Surveillance(半平面交)

2013-10-15 16:54 295 查看
题目链接

2Y,模版抄错了一点。

#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
using namespace std;
#define eps 1e-8
#define N 2001
struct point
{
double x,y;
}p
,pre
,temp
;
double a,b,c;
int n,m;
void getline(point x,point y)
{
a = y.y - x.y;
b = x.x - y.x;
c = y.x * x.y - x.x * y.y;
}
point intersect(point x,point y)
{
double u = fabs(a*x.x + b*x.y + c);
double v = fabs(a*y.x + b*y.y + c);
point ans;
ans.x = (x.x*v+y.x*u)/(u+v);
ans.y = (x.y*v+y.y*u)/(u+v);
return ans;
}
void cut()
{
int num = 0,i;
for(i = 1;i <= m;i ++)
{
if(a*p[i].x + b*p[i].y + c > -eps)
{
temp[++num] = p[i];
}
else
{
if(a*p[i-1].x + b*p[i-1].y + c > eps)
temp[++num] = intersect(p[i],p[i-1]);
if(a*p[i+1].x + b*p[i+1].y + c > eps)
temp[++num] = intersect(p[i],p[i+1]);
}
}
for(i = 1;i <= num;i ++)
p[i] = temp[i];
p[0] = p[num];
p[num+1] = p[1];
m = num;
}
void fun()
{
int i;
m = n;
for(i = 1;i <= n;i ++)
{
getline(pre[i],pre[i+1]);
cut();
}
}
int main()
{
int i,cas = 1;
while(scanf("%d",&n)!=EOF)
{
if(!n) break;
for(i = 1;i <= n;i ++)
{
scanf("%lf%lf",&pre[i].x,&pre[i].y);
p[i] = pre[i];
}
pre[n+1] = pre[1];
p[n+1] = p[1];
p[0] = p
;
fun();
printf("Floor #%d\n",cas ++);
if(m)
printf("Surveillance is possible.\n");
else
printf("Surveillance is impossible.\n");
printf("\n");
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: