POJ 1474 Video Surveillance (多边形内核判断)
2015-10-02 12:37
363 查看
【题目链接】click here~~
【题目大意】:多边形内核的判断
【思路】:模板题
代码:
【题目大意】:多边形内核的判断
【思路】:模板题
代码:
/* * Problem: POJ No.1474 * Running time: 125MS * Complier: G++ * Author: herongwei * Create Time: 12:27 2015/10/2 星期五 */ #include <math.h> #include <stdio.h> #include <string.h> #include <iostream> #include <algorithm> using namespace std; const double pi=acos(-1.0); const double e=exp(1.0); const double eps=1e-8; const int maxn=105; struct Point{ double x,y; }point[maxn]; Point temp[maxn]; Point p[maxn]; int pre_point ,last_point; double a,b,c; void getline(Point x,Point y)//获取直线ax+by+c==0 { 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)//获取直线ax+by+c==0 和点x和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()//用直线ax+by+c==0切割多边形 { int cut_num=0; for(int i=1; i<=last_point; ++i) { if(a*p[i].x+b*p[i].y+c>=0){ temp[++cut_num]=p[i]; } else { if(a*p[i-1].x+b*p[i-1].y+c>0) { temp[++cut_num]=intersect(p[i-1],p[i]); } if(a*p[i+1].x+b*p[i+1].y+c>0) { temp[++cut_num]=intersect(p[i+1],p[i]); } } } for(int i=1; i<=cut_num; ++i) { p[i]=temp[i]; } p[cut_num+1]=temp[1]; p[0]=temp[cut_num]; last_point=cut_num; } void solve() { for(int i=1; i<=pre_point; ++i){ p[i]=point[i]; } point[pre_point+1]=point[1]; p[pre_point+1]=p[1]; p[0]=p[pre_point]; last_point=pre_point; for(int i=1; i<=pre_point; ++i) { getline(point[i],point[i+1]);//根据point[i]和point[i+1]确定直线ax+by+c==0 cut();//用直线ax+by+c==0切割多边形 } } int main() { int tot=1; while(cin>>pre_point&&pre_point){ for(int i=1; i<=pre_point; ++i){ cin>>point[i].x>>point[i].y; } solve(); printf("Floor #%d\n",tot++); if(last_point==0) puts("Surveillance is impossible."),puts(""); else puts("Surveillance is possible."),puts(""); } return 0; } /* 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 Floor #1 Surveillance is possible. Floor #2 Surveillance is impossible. */
相关文章推荐
- 操作系统作业~分页式存储管理(作业)
- 黑马程序员————Java网络通讯编程详解
- 黑马程序员————Java多线程技术详解
- 哈夫曼编码的简单实例
- leetcode 066 Plus One(难易度:Easy)
- Alpha-expansion and Alpha-beta-swap Algorithm Flow
- java.lang.OutOfMemoryError: Java heap space
- 不一样的命令行 – Windows PowerShell简介
- 观察者模式
- Xcode 5 + iOS 7免证书(iDP)真机调试与生成IPA全攻略
- 黑马程序员————Java的基础知识详解
- car的旅行路线(floyd算法)
- XCode6.0 的iOS免证书真机测试方法
- javascript学习笔记1
- Shark machine learning library在linux下的安装
- 8个必备的PHP功能开发
- 黑马程序员————Java的IO流的详解
- POJ 1279 Art Gallery (多边形组成的内核面积)
- Linux网络配置总结
- JAVA实现输入一个整数,输出该数二进制表示中1的个数(《剑指offer》)