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

牛牛们,帮我看一下,确实wa的不知道怎么弄了...

Posted by yujiashan at 2006-12-22 21:25:52 on Problem 1410
基本思路是:
            分别判断矩形的四条边是否与线段相交。
            (两线段重叠不算相交)
                                                          谢谢了!
#include<stdio.h>
double xs,ys,xe,ye,a,b,c,d;
void solve()
{
     double temp,xl=(a<c)?a:c,xr=(a>c)?a:c,yt=(b>d)?b:d,yb=(b<d)?b:d,xi=(xs<xe)?xs:xe,xa=(xs>xe)?xs:xe,yi=(ys<ye)?ys:ye,ya=(ys>ye)?ys:ye;
     if (xe==xs)
     {
        if (xe==xl||xe==xr)
        {
           if (yi==yt)
           {
              printf("T\n");
              return;
           }
           if (ya==yb)
           {
              printf("T\n");
              return;
           }
           printf("F\n");
           return;
        }
        if (xe>xl&&xe<xr)
        {
           if (yi>yt)
           {
              printf("F\n");
              return;
           }
           if (ya<yb)
           {
              printf("F\n");
              return;
           }
           if (yi>yb&&ya<yt)
           {
              printf("F\n");
              return;
           }
           printf("T\n");
           return;
        }
        printf("F\n");
        return;
     }
     if (ye==ys)
     {
        if (ye==yb||ye==yt)
        {
           if (xi==xr)
           {
              printf("T\n");
              return;
           }
           if (xa==xl)
           {
              printf("T\n");
              return;
           }
           printf("F\n");
           return;
        }
        if (ye>yb&&ye<yt)
        {
           if (xi>xr)
           {
              printf("F\n");
              return;
           }
           if (xa<xl)
           {
              printf("F\n");
              return;
           }
           if (xi>xl&&xa<xr)
           {
              printf("F\n");
              return;
           }
           printf("T\n");
           return;
        }
        printf("F\n");
        return;
     }
     temp=((xe-xs)*(yt-ye))/(ye-ys)+xe;
     if (temp>=xl&&temp<=xr&&temp>=xi&&temp<=xa)
     {
        printf("T\n");
        return;
     }
     temp=((xe-xs)*(yb-ye))/(ye-ys)+xe;
     if (temp>=xl&&temp<=xr&&temp>=xi&&temp<=xa)
     {
        printf("T\n");
        return;
     }
     temp=(ye-ys)*(xl-xe)/(xe-xs)+ye;
     if (temp>=yb&&temp<=yt&&temp>=yi&&temp<=ya)
     {
        printf("T\n");
        return;
     }
     temp=(ye-ys)*(xr-xe)/(xe-xs)+ye;
     if (temp>=yb&&temp<=yt&&temp>=yi&&temp<=ya)
     {
        printf("T\n");
        return;
     }
     printf("F\n");
}
int main()
{
    int n;
    scanf("%d",&n);
    while (n--)
    {
          scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&xs,&ys,&xe,&ye,&a,&b,&c,&d);
          solve();
    }
    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