POJ 1066 线段相交
来源:互联网 发布:哪里能买到特效软件 编辑:程序博客网 时间:2024/05/16 17:36
题目的意思换句话说:就是要你以线段中的某个点和财宝(treasure)所在点连成一条直线,使得其和其它线段交点数最少;
这样理解的条件是: 财宝点 不在墙上.题目已给出,满足;
另外注意的是,初始化最小值肯定是一个很大的值inf; 如果最后得到的是inf,那就置为0(最后为1); 可能很多人错在这儿
#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#include <algorithm>#include <queue>using namespace std;#define INF 0x3f3f3f3fconst int maxn = 30+3;#define eps 1e-8struct Point{ float x; float y;}p[maxn*2],P0;int Sig(float x){ return (x > eps) - (x < -eps);}float Mult(Point p0, Point p1, Point p2){ return (p1.x-p0.x)*(p2.y-p0.y) - (p2.x-p0.x)*(p1.y-p0.y);}int line_in_line(Point p1, Point p2, Point p3, Point p4){ return ( Sig(Mult(p1,p3,p2))*Sig(Mult(p1,p4,p2)) < 0 && Sig(Mult(p3,p1,p4))*Sig(Mult(p3,p2,p4)) < 0 );}int main(){#ifndef ONLINE_JUDGE freopen("in","r",stdin);#endif int n; cin>>n; for(int i = 0; i < n*2; i += 2) { cin>>p[i].x>>p[i].y>>p[i+1].x>>p[i+1].y; } cin>>P0.x>>P0.y; int MIN = INF, num = 0; for(int i = 0; i < n*2; i++) { num = 0; for(int j = 0; j < n*2-1; j += 2) { if(line_in_line(P0,p[i],p[j],p[j+1])) num++; }// cout<<i<<" "<<num<<endl; MIN = num < MIN ? num: MIN; } if(MIN == INF ) MIN = 0; cout<<"Number of doors = "<<MIN+1<<endl; return 0;}
- POJ 1066 线段相交
- POJ 1066 线段相交
- POJ 1066 线段相交
- POJ 1066 判断线段相交
- POJ 1066 线段相交判断
- POJ 1066 Treasure Hunt (线段相交)
- poj 1066 Treasure Hunt(判断线段相交)
- POJ 1066 两线段的规范相交
- POJ 1066 Treasure Hunt --几何,线段相交
- POJ 1066 Treasure Hunt(线段相交判断)
- POJ 1066 Treasure Hunt(线段相交判断)
- poj 1066 判断线段相交 思维
- POJ 1066 Treasure Hunt 【线段相交】
- POJ 1556 线段相交
- POJ 2653 线段相交
- poj 1127(线段相交)
- POJ 2653 线段相交
- POJ 1066 Treasure Hunt (线段与线段相交) -
- 宽度优先搜索——迷宫的最短路径
- Linux端口的关闭和启用
- u-boot命令实现
- 如何在ashx页面获取Session值
- Eclipse选中变量名,相同变量都变色显示 的设置
- POJ 1066 线段相交
- linux有点奇怪
- iOS 6 SDK: 在应用内展示App Store
- 【Deep Learning】4、Self-Taught Learning
- 子网掩码与子网划分
- 服务器编程之fork并行模式
- 机器学习前沿热点–Deep Learning(一)
- 史上最详细的struts 2 标签整理
- POJ 3468