POJ 1269 Intersecting Lines

简单细节题。输出的时候%.2lf C++能过,G++过不了。改成%.2f G++才能过......

#include<cstdio>
#include<cstring>
#include<cmath>
#include<stack>
#include<vector>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;


struct J
{
    int fz,fm;
    int zf;
};
vector<J>Q;

struct Line
{
    int a,b,c;
}line1,line2;
int T;
int X1,Y1,X2,Y2,X3,Y3,X4,Y4;

int gcd(int a, int b)
{
    if (a%b==0) return b;
    return gcd(b,a%b);
}

int main()
{
    scanf("%d",&T);
    printf("INTERSECTING LINES OUTPUT\n");
    while(T--)
    {
        scanf("%d%d%d%d%d%d%d%d",&X1,&Y1,&X2,&Y2,&X3,&Y3,&X4,&Y4);
        Q.clear();

        line1.a=Y2-Y1;
        line1.b=X2-X1;
        line1.c=Y2*(X2-X1)-X2*(Y2-Y1);

        line2.a=Y4-Y3;
        line2.b=X4-X3;
        line2.c=Y4*(X4-X3)-X4*(Y4-Y3);

        bool fail=0;
        if(line1.a==0&&line2.a!=0) fail=1;
        if(line1.b==0&&line2.b!=0) fail=1;
        if(line1.c==0&&line2.c!=0) fail=1;
        if(line1.a!=0&&line2.a==0) fail=1;
        if(line1.b!=0&&line2.b==0) fail=1;
        if(line1.c!=0&&line2.c==0) fail=1;
        if(fail==0)
        {
            if(line1.a==0&&line2.a==0){}
            else {
                int num=0,zf;
                if(line1.a>0) num++;
                if(line2.a>0) num++;
                if(num%2==0) zf=1;
                else zf=-1;
                J r;
                r.zf=zf;
                r.fz=r.zf*abs(line1.a)/gcd(abs(line1.a),abs(line2.a));
                r.fm=abs(line2.a)/gcd(abs(line1.a),abs(line2.a));
                Q.push_back(r);
            }

            if(line1.b==0&&line2.b==0){}
            else {
                int num=0,zf;
                if(line1.b>0) num++;
                if(line2.b>0) num++;
                if(num%2==0) zf=1;
                else zf=-1;
                J r;
                r.zf=zf;
                r.fz=r.zf*abs(line1.b)/gcd(abs(line1.b),abs(line2.b));
                r.fm=abs(line2.b)/gcd(abs(line1.b),abs(line2.b));
                Q.push_back(r);
            }

            if(line1.c==0&&line2.c==0){}
            else {
                int num=0,zf;
                if(line1.b>0) num++;
                if(line2.b>0) num++;
                if(num%2==0) zf=1;
                else zf=-1;
                J r;
                r.zf=zf;
                r.fz=r.zf*abs(line1.c)/gcd(abs(line1.c),abs(line2.c));
                r.fm=abs(line2.c)/gcd(abs(line1.c),abs(line2.c));
                Q.push_back(r);
            }
            int biaozhunA=Q[0].fz;
            int biaozhunB=Q[0].fm;
            for(int i=0;i<Q.size();i++)
                if(Q[i].fz!=biaozhunA||Q[i].fm!=biaozhunB) fail=1;
        }
        if(fail==0) {printf("LINE\n");continue;}
        else
        {
            if(line1.a*line2.b==line2.a*line1.b) {printf("NONE\n");continue;}
            else
            {
                double ansX=1.0*(line1.b*line2.c-line2.b*line1.c)/(line1.a*line2.b-line2.a*line1.b);
                double ansY=-1.0*(line2.a*line1.c-line1.a*line2.c)/(line1.a*line2.b-line2.a*line1.b);
                printf("POINT %.2lf %.2lf\n",ansX,ansY);
            }
        }
    }
    printf("END OF OUTPUT\n");
    return 0;
}

 

posted @ 2016-01-22 09:28  Fighting_Heart  阅读(151)  评论(0编辑  收藏  举报