• joj 1131 Intersection


    一道wa了n+1次的题,都快绝望了,本想求助于网络上的各种代码,却发现一律模板,话说我现在还不知道模板为何物。。。。。。。终于在我的绞尽脑汁之下找到了错误,心情very舒畅,方法是看直线和矩形的各个边能不能相交(规范和非规范)以及他会不会在矩形里边:

    #include<iostream>
    #include<stdio.h>
    using namespace std;
    struct point{
        int x;
        int y;
    };
    int det(int a,int b,int c,int d)
    {
        return a*d-b*c;
    }
    int cross(point a,point b,point c)
    {
        int n=det(b.x-a.x,b.y-a.y,c.x-a.x,c.y-a.y);
        return n;
    }
    int main()
    {
        int total_case,iii;
        scanf("%d",&total_case);
        for(iii=0;iii<total_case;iii++)
        {
            point start,end,l_t,l_b,r_t,r_b;
            scanf("%d%d%d%d%d%d%d%d",&start.x,&start.y,&end.x,&end.y,&l_t.x,&l_t.y,&r_b.x,&r_b.y);
            l_b.x=l_t.x;
            l_b.y=r_b.y;
            r_t.x=r_b.x;
            r_t.y=l_t.y;
            if(start.x==end.x)                                                                                         // 就是因为忘了这个才悲剧n次
            {
                if((start.y>l_t.y&&end.y>l_t.y)||(start.y<r_b.y&&end.y<r_b.y))
                {
                    printf("F\n");
                    continue;
                }
            }
            if(start.y==end.y)
            {
                if((start.x>r_b.x&&end.x>r_b.x)||(start.x<l_t.x&&end.x<l_t.x))
                {
                    printf("F\n");
                    continue;
                }
            }
            if(start.x>=l_t.x&&start.x<=r_b.x&&start.y<=l_t.y&&start.y>=r_b.y)
            {
                printf("T\n");
                continue;
            }
            int d1=cross(start,end,l_t);
            int d2=cross(start,end,r_t);
            int d3=cross(start,end,l_b);
            int d4=cross(start,end,r_b);
            int p1=cross(l_t,r_t,start);
            int p2=cross(l_t,r_t,end);
            int p3=cross(l_t,l_b,start);
            int p4=cross(l_t,l_b,end);
            int p5=cross(l_b,r_b,start);
            int p6=cross(l_b,r_b,end);
            int p7=cross(r_b,r_t,start);
            int p8=cross(r_b,r_t,end);
            if(d1*d2<=0&&p1*p2<=0)    //上
            {
                printf("T\n");
                continue;
            }
            if(d3*d4<=0&&p5*p6<=0)    //下
            {
                printf("T\n");
                continue;
            }
            if(d1*d3<=0&&p3*p4<=0)     //左
            {
                printf("T\n");
                continue;
            }
            if(d4*d2<=0&&p7*p8<=0)     //右
            {
                printf("T\n");
                continue;
            }
            printf("F\n");
        }
    }

  • 相关阅读:
    [转]对Lucene PhraseQuery的slop的理解
    Best jQuery Plugins of 2010
    15 jQuery Plugins To Create A User Friendly Tooltip
    Lucene:基于Java的全文检索引擎简介
    9 Powerful jQuery File Upload Plugins
    Coding Best Practices Using DateTime in the .NET Framework
    Best Image Croppers ready to use for web developers
    28 jQuery Zoom Plugins Creating Stunning Image Effect
    VS2005 + VSS2005 实现团队开发、源代码管理、版本控制(转)
    禁止状态栏显示超链
  • 原文地址:https://www.cnblogs.com/dchipnau/p/4985964.html
Copyright © 2020-2023  润新知