Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

留个纪念。。。

Posted by 280516804 at 2011-08-15 15:24:56 on Problem 1269
#include<cstdio>
#include<cmath>
#define eps 1e-10
struct point{double x,y;}p[210];
int zero(double a)
{
    if(fabs(a)<eps)return 0;
    return (a>0)?1:-1;
}
double det(double x1,double x2,double y1,double y2)
{
    return x1*y2-x2*y1;
}
double cross(point a,point b,point c)
{
    return det(b.x-a.x,b.y-a.y,c.x-a.x,c.y-a.y);
}
void dcross(point a,point b,point c,point d)
{
    double size1=cross(a,b,c);
    double size2=cross(a,b,d);
    point ret;
    if(zero(size1)==0&&zero(size2)==0)
    {
        printf("LINE\n");
        return;
    }
    if(zero(size1-size2)==0)
    {
        printf("NONE\n");
        return;
    }
    if(zero(size1)==0)
    {
        ret.x=c.x;
        ret.y=c.y;
    }
    else if(zero(size2)==0)
    {
        ret.x=d.x;
        ret.y=d.y;
    }
    else
    {
        ret.x=(size1*d.x-size2*c.x)/(size1-size2);
        ret.y=(size1*d.y-size2*c.y)/(size1-size2);
    }
    printf("POINT %.2f %.2f\n",ret.x,ret.y);
    return;
}
int main()
{
    int ti;
    scanf("%d",&ti);
    printf("INTERSECTING LINES OUTPUT\n");
    while(ti--)
    {
        point a[4];
        for(int i=0;i<4;i++)scanf("%lf%lf",&a[i].x,&a[i].y);
        dcross(a[0],a[1],a[2],a[3]);
    }
    printf("END OF OUTPUT\n");
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator