ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1348. Goat in the Garden 2

Why I get wa?Many tests I have passed?help!!!
Posted by gbaoxing 28 Oct 2011 14:40
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
struct node
{
    int x,y;
}A,B,C;
double length(int x1,int y1,int x2,int y2)
{
    double x=x1-x2;
    double y=y1-y2;
    return sqrt(x*x+y*y);
}
int Abs(int x)
{
    return x>0?x:-x;
}
int main()
{
    int l,min,max;
    double l1,l2,m1,m2;
    m2=-9999999;
    scanf("%d%d%d%d%d%d%d",&A.x,&A.y,&B.x,&B.y,&C.x,&C.y,&l);
    double s1;
    s1=length(A.x,A.y,C.x,C.y);
    if(s1>m2)
    m2=s1;
    s1=length(B.x,B.y,C.x,C.y);
    if(s1>m2)
    m2=s1;
    m2-=l;
    if(A.x-B.x==0)
    {
        min=A.y>B.y?B.y:A.y;
        max=A.y>B.y?A.y:B.y;
        if(C.y>=min&&C.y<=max)
        {
            m1=Abs(C.x-A.x);
            m1-=l;
        }
        else
        {
                l1=length(A.x,A.y,C.x,C.y);
                l2=length(B.x,B.y,C.x,C.y);
                m1=l1>l2?l2:l1;
                m1-=l;
        }
    }
    else
    {
        int k1,b1,k2,b2;
        k1=(A.y-B.y)/(A.x-B.x);
        if(k1==0)
        {
            min=A.x>B.x?B.x:A.x;
            max=A.x>B.x?A.x:B.x;
            if(C.x>=min&&C.x<=max)
            {
                m1=Abs(C.y-A.y);
                m1-=l;
            }
            else
            {
                l1=length(A.x,A.y,C.x,C.y);
                l2=length(B.x,B.y,C.x,C.y);
                m1=l1>l2?l2:l1;
                m1-=l;
            }
        }
        else
        {
             min=A.y>B.y?B.y:A.y;
            max=A.y>B.y?A.y:B.y;
            k2=-(1/k1);
            b1=A.y-k1*A.x;
            b2=C.y-k2*C.x;
           int x,y;
            x=(b2-b1)/(k1-k2);
            y=k1*x+b1;
            //printf("%lf %lf\n",x,y);
            if(y>=min&&y<=max)
            {
                m1=length(C.x,C.y,x,y);
                m1-=l;
            }
            else
            {
                l1=length(A.x,A.y,C.x,C.y);
                l2=length(B.x,B.y,C.x,C.y);
                m2=l1>l2?l2:l1;
                m2-=l;
            }
        }
    }
    printf("%.2lf\n%.2lf\n",m1>0?m1:0,m2>0?m2:0);
    return 0;
}
2 1 4 2 0 0 1
-5 0 5 0 0 5 100
1 1 1 1 10 10 100
-2 6 2 6 0 0 0
-1 1 1 1 -4 -3 0
1 2 1 1 0 0 0
1 1 1 1 0 0 0
All these test I have passed >