zoukankan      html  css  js  c++  java
  • poj 1269 水题

    题目链接:http://poj.org/problem?id=1269

    #include<cstdio>
    #include<cstring>
    #include<cmath>
    #include<iostream>
    #include<algorithm>
    #include<queue>
    using namespace std;
    const int maxn = 105;
    const int maxe = 20000;
    const int INF = 0x3f3f3f;
    const double eps = 1e-8;
    const double PI = acos(-1.0);
    
    struct Point{
        double x,y;
        Point(double x=0, double y=0) : x(x),y(y){ }    //构造函数
    };
    typedef Point Vector;
    
    Vector operator + (Vector A , Vector B){return Vector(A.x+B.x,A.y+B.y);}
    Vector operator - (Vector A , Vector B){return Vector(A.x-B.x,A.y-B.y);}
    Vector operator * (Vector A , double p){return Vector(A.x*p,A.y*p);}
    Vector operator / (Vector A , double p){return Vector(A.x/p,A.y/p);}
    
    bool operator < (const Point& a,const Point& b){
        return a.x < b.x ||( a.x == b.x && a.y < b.y);
    }
    int dcmp(double x){
        if(fabs(x) < eps) return 0;
        else              return x < 0 ? -1 : 1;
    }
    bool operator == (const Point& a, const Point& b){
        return dcmp(a.x - b.x) == 0 && dcmp(a.y - b.y) == 0;
    }
    
    double Dot(Vector A, Vector B){ return A.x*B.x + A.y*B.y; }
    double Cross(Vector A, Vector B)  { return A.x*B.y - A.y * B.x; }
    double Length(Vector A)    { return sqrt(Dot(A,A)); }
    
    
    Point GetLineIntersecion(Point P, Vector v,Point Q,Vector w){
        Vector u = P - Q;
        double t = Cross(w,u)/Cross(v,w);
        return P + v*t;
    }
    
    Point read_point(){
        Point A;
        scanf("%lf %lf",&A.x,&A.y);
        return A;
    }
    
    /******************************分割线*******************************/
    
    Point P1,P2,Q1,Q2;
    int N;
    
    int main()
    {
     //  freopen("E:\acm\input.txt","r",stdin);
       cin>>N;
       printf("INTERSECTING LINES OUTPUT
    ");
       while(N--){
          P1 = read_point();
          P2 = read_point();
          Q1 = read_point();
          Q2 = read_point();
          if(dcmp(Cross(P2-P1,Q2-Q1))==0){ //平行或重合;
             if(dcmp(Cross(P1-Q1,P1-Q2)) == 0)  printf("LINE
    ");
             else                               printf("NONE
    ");
          }
          else{  //相交;
             Point A = GetLineIntersecion(P1,P2-P1,Q1,Q2-Q1);
             printf("POINT %.2f %.2f
    ",A.x,A.y);
          }
       }
       printf("END OF OUTPUT
    ");
    }
    View Code
  • 相关阅读:
    找水王
    第十四周学习记录
    第十三周学习记录
    第十二周学习记录
    序列化
    哪个元素出发事件
    阻止默认行为-event.preventDefault();
    阻止时间冒泡 -event.stopPropagation();
    HTML5的LocalStorage和sessionStorage的使用 -缓存
    同步加载、异步加载、延迟加载
  • 原文地址:https://www.cnblogs.com/acmdeweilai/p/3251977.html
Copyright © 2011-2022 走看看