POJ 2624 4th Point

来源:互联网 发布:手机上编程 编辑:程序博客网 时间:2024/06/05 05:08

这题有一个陷阱,那就是点会随意给出,并不是第二个点与第三个点相同,所以要做处理。

还有一个点就是double用%f输出。

////  main.cpp//  Richard////  Created by 邵金杰 on 16/8/6.//  Copyright © 2016年 邵金杰. All rights reserved.//#include<cstdio>#include<vector>using namespace std;typedef pair<double,double> CVector;typedef pair<double,double> CPoint;typedef pair<CPoint,CPoint> CLine;CVector operator + (CVector p,CVector q){    return CVector(p.first+q.first,p.second+q.second);}CVector operator - (CPoint p,CPoint q){    return CVector(p.first-q.first,p.second-q.second);}bool operator == (CPoint p,CPoint q){    return p.first==q.first&&p.second==q.second;}int main(){    double x1,y1,x2,y2,x3,y3,x4,y4;    while(scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4)!=EOF)    {        CLine p=CLine(CPoint(x1,y1),CPoint(x2,y2));        CLine q=CLine(CPoint(x3,y3),CPoint(x4,y4));        if(p.first==q.first) {CPoint t=p.first;p.first=p.second;p.second=t;}        else if(p.first==q.second) {            CPoint t1=p.first;p.first=p.second;p.second=t1;            CPoint t2=q.first;q.first=q.second;q.second=t2;        }        else if(p.second==q.second){CPoint t=q.first;q.first=q.second;q.second=t;}        CVector v1=p.first-p.second;        CVector v2=q.second-q.first;        CPoint  m=q.first+(v1+v2);        printf("%.3f %.3f\n",m.first,m.second);    }    return 0;}

0 0
原创粉丝点击