POJ 2074 Line of Sight
来源:互联网 发布:淘宝卖家怎么查看访客 编辑:程序博客网 时间:2024/06/06 10:06
POJ 2074 Line of Sight
线段相交
其实就是枚举障碍物的坐端点和房子的右端点 还有就是障碍的右端点和房子的左端点构成的直线和风景的交点对;
然后就是求这中间没有被覆盖的最长的长度。
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<vector>using namespace std;#define FOR(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)#define DOR(i,a,b) for(int (i)=(a);(i)>=(b);(i)--)#define oo 1e6#define eps 1e-8#define nMax 100000#define mp make_pair#define pb push_back#define F first#define S second#define bug puts("OOOOh.....");#define zero(x) (((x)>0?(x):-(x))<eps)int dcmp(double x){ if(fabs(x)<eps) return 0; return x>0?1:-1;}class point {public: double x,y; point (double x=0,double y=0):x(x),y(y) {} void make(double _x,double _y) {x=_x;y=_y;} void read() { scanf("%lf%lf",&x,&y); } void out() { printf("%.2lf %.2lf\n",x,y);} double len() { return sqrt(x*x+y*y); } point friend operator - (point const& u,point const& v) { return point(u.x-v.x,u.y-v.y); } point friend operator + (point const& u,point const& v) { return point(u.x+v.x,u.y+v.y); } double friend operator * (point const& u,point const& v) { return u.x*v.y-u.y*v.x; } double friend operator ^ (point const& u,point const& v) { return u.x*v.x+u.y*v.y; } point friend operator * (point const& u,double const& k) { return point(u.x*k,u.y*k); }};typedef class line{public: point a,b; line() {} line (point a,point b):a(a),b(b){} void make(point u,point v) {a=u;b=v;}void make(double x1,double x2,double y){make(point(x1,y),point(x2,y));} void read() { scanf("%lf%lf%lf",&a.x,&b.x,&a.y);b.y=a.y; }friend double intersection(line u,line v);}segment;double intersection(line u,line v){point ret=u.a;double t=(u.a-v.a)*(v.a-v.b)/((u.a-u.b)*(v.a-v.b));ret = ret + (u.b-u.a)*t;return ret.x;}line H,P,s[nMax];int n;vector<pair<double,double> > V;void sovle(){V.clear();for(int i=1;i<=n;i++) {if(dcmp(H.a.y-s[i].a.y)>0 && dcmp(s[i].a.y-P.a.y)>0){V.pb(mp(intersection(line(H.b,s[i].a),P),intersection(line(H.a,s[i].b),P)));}}V.pb(mp(P.b.x,P.b.x));sort(V.begin(),V.end());double ans=0;double nb=P.a.x;for(int i=0;i<V.size();i++) {if(dcmp(V[i].F-nb)>0) {ans = max(ans,V[i].F-nb);}if(dcmp(V[i].S-nb)>0){nb=V[i].S;}}if(dcmp(ans)==0) printf("No View\n");else printf("%.2lf\n",ans + eps);return ;}int main(){#ifndef ONLINE_JUDGEfreopen("input.txt","r",stdin);#endif double x1,x2,y;while(~scanf("%lf%lf%lf",&x1,&x2,&y),dcmp(x1)||dcmp(x2)||dcmp(y)){H.make(x1,x2,y);P.read();scanf("%d",&n);FOR(i,1,n) s[i].read();sovle();}return 0;}
- POJ 2074 Line of Sight
- poj 2074 Line of Sight
- Poj 2074 Line of Sight
- POJ 2074 Line of Sight
- POJ 2074 Line of Sight
- poj 2074 Line of Sight
- POJ 2074 Line of Sight
- poj 2074Line of Sight
- poj 2074 Line of Sight
- POJ 2074 Line of Sight(求交点)
- POJ 2074 Line of Sight 直线交
- Line of Sight - POJ 2074 直线交点
- POJ 2074 Line of Sight <几何>
- POJ 2074 Line of Sight(判线段与直线相交)
- poj 2074 Line of Sight(计算几何)
- POJ 2074 Line of Sight 直线相交+线段覆盖
- poj2074 Line of Sight
- Poj.2074 Line of Sight【计算几何-线段】 2015/08/28
- hdu-4217Data Structure?
- 40多个关于人脸检测/识别的API、库和软件
- MySQL使用rand获取随机记录的性能优化问题
- ATM机基本操作代码
- 内存碎片导致应用不断被杀的问题
- POJ 2074 Line of Sight
- 详细解析Linux scp命令的应用
- Hbase Replication 介绍
- poj-3468-A Simple Problem with Integers
- 割点&割边模板
- 学生信息管理系统之深度理解
- Oracle 11g 提示没有scott用户,无法解锁
- PyQT5 安装后不能运行的问题
- poj 3164 最小树形图 初识朱刘算法