| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
G++WA,C++AC?#include<cstdio>
#include<cmath>
using namespace std;
const double eps=1e-8;
inline bool equal(double x,double y){return abs(x-y)<eps;}
inline bool zero(double x){return abs(x)<eps;}
struct point{
double x,y;
point(){}
point(double x,double y):x(x),y(y){}
bool operator==(point q){return equal(x,q.x)&&equal(y,q.y);}
};
typedef point vector;
inline vector operator-(vector a){return vector(-a.x,-a.y);}
inline vector operator+(vector a,vector b){return vector(a.x+b.x,a.y+b.y);}
inline vector operator-(vector a,vector b){return vector(a.x-b.x,a.y-b.y);}
inline vector operator*(vector a,double b){return vector(a.x*b,a.y*b);}
inline vector operator/(vector a,double b){return vector(a.x/b,a.y/b);}
double operator*(vector a,vector b){return a.x*b.y-b.x*a.y;}//cross product
double operator^(vector a,vector b){return a.x*b.x+a.y*b.y;}//dot product
point intersection(point p,vector v,point q,vector w){
vector u=p-q;
return p+v*((w*u)/(v*w));
}
int main(){
point a,b,c,d;
int n;
scanf("%d",&n);
printf("INTERSECTING LINES OUTPUT\n");
while(n--){
scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&a.x,&a.y,&b.x,&b.y,&c.x,&c.y,&d.x,&d.y);
vector v=b-a,w=d-c;
if(zero(v*w)){
if(zero(v*(c-b))) printf("LINE\n");
else printf("NONE\n");
}else{
point inter=intersection(a,v,c,w);
printf("POINT %.2lf %.2lf\n",inter.x,inter.y);
}
}
printf("END OF OUTPUT\n");
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator