poj1254Hansel and Grethel
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
const double eps=1e-10;
const double pi=acos(-1.0);
const int inf=1e8;
inline int dcmp(double x){
if(x < eps) return 0;
return x>0?1:-1;
}
struct pt{
double x,y;
pt(){}
pt(int xx,int yy):x(xx),y(yy){}
friend pt operator - (pt a,pt b){
return pt(a.x-b.x,a.y-b.y);
}
};
inline double cross(pt a,pt b){
return a.x*b.y-a.y*b.x;
}
inline void intersect_line(pt a,pt b,pt c,pt d){
//cout<<cross(a-b,c-d)<<endl;
double t=cross(a-c,c-d)/cross(a-b,c-d);
//cout<<t<<endl;
//cout<<a.x+(b.x-a.x)*t<<endl;
printf("%.4f %.4f\n",(a.x+(b.x-a.x)*t),(a.y+(b.y-a.y)*t));
}
inline int xulv(int k){
if(k>0 && k<=90) return (90-k);
if(k>90 && k<270)return (270-k);
if(k>=270 && k<360)return (450-k);
}
int main(){
int T,d[2];
pt p[4];
cin>>T;
while(T--){
for(int i=0;i<2;i++)
scanf("%lf%lf%d",&p[i].x,&p[i].y,&d[i]);
if(d[0]==0 ||d[0]==360){
p[2].y=p[0].y+10.0;
p[2].x=p[0].x;
}
else{
int k=xulv(d[0]);
p[2].x=p[0].x+inf*cos(k*pi/180);
p[2].y=p[0].y+inf*sin(k*pi/180);
}
if(d[1]==0 ||d[1]==360){
p[3].x=p[1].x;
p[3].y=p[1].y+10.0;
}
else{
int k=xulv(d[1]);
p[3].x=p[1].x+inf*cos(k*pi/180);
p[3].y=p[1].y+inf*sin(k*pi/180);
}
//for(int i=0;i<4;i++)
//printf("%lf %lf\n",p[i].x,p[i].y);
intersect_line(p[0],p[2],p[1],p[3]);
}
return 0;
}
poj1269Intersecting_Lines
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const double eps=1e-10;
inline int dcmp(int x){
if(!x) return 0;
return x>0?1:-1;
}
struct pt{
int x,y;
pt(){}
pt(int xx,int yy):x(xx),y(yy){}
friend pt operator -(pt a,pt b){
return pt(a.x-b.x,a.y-b.y);
}
};
inline int cross(pt a,pt b){
return a.x*b.y-a.y*b.x;
}
void intersect_line(pt a,pt b,pt c,pt d){
if(dcmp(cross(a-b,c-d))==0){
if(!dcmp(cross(c-a,d-a))) {
cout<<"LINE"<<endl;
return ;
}
else{
cout<<"NONE"<<endl;
return;
}
}
double t=cross(a-c,c-d)*1.0/cross(a-b,c-d);
//cout<<'a'<<t<<endl;
double x=a.x,y=a.y;
x+=(double)(b.x-a.x)*t;
y+=(double)(b.y-a.y)*t;
//cout<<ret.x<<' '<<ret.y<<endl;
printf("POINT %.2lf %.2lf\n",x,y);
}
int main(){
int T,i;
cin>>T;
cout<<"INTERSECTING LINES OUTPUT"<<endl;
while(T--){
pt p[4];
for(i=0;i<4;i++){
scanf("%d%d",&p[i].x,&p[i].y);
}
intersect_line(p[0],p[1],p[2],p[3]);
//if(tmp.second==0)cout<<"LINE"<<endl;
//else if(tmp.second==1)cout<<"NONE"<<endl;
//else{
// cout<<"POINT "<<tmp.first.x<<' '<<tmp.first.y<<endl;
//}
}
cout<<"END OF OUTPUT"<<endl;
return 0;
}