• Moon Game (凸四边形个数,数学题)


    Problem 2148 Moon Game

    Accept: 24    Submit: 61 Time Limit: 1000 mSec    Memory Limit : 32768 KB

    Problem Description

    Fat brother and Maze are playing a kind of special (hentai) game in the clearly blue sky which we can just consider as a kind of two-dimensional plane. Then Fat brother starts to draw N starts in the sky which we can just consider each as a point. After he draws these stars, he starts to sing the famous song “The Moon Represents My Heart” to Maze.

    You ask me how deeply I love you,

    How much I love you?

    My heart is true,

    My love is true,

    The moon represents my heart.

    But as Fat brother is a little bit stay-adorable(呆萌), he just consider that the moon is a special kind of convex quadrilateral and starts to count the number of different convex quadrilateral in the sky. As this number is quiet large, he asks for your help.

    Input

    The first line of the date is an integer T, which is the number of the text cases.

    Then T cases follow, each case contains an integer N describe the number of the points.

    Then N lines follow, Each line contains two integers describe the coordinate of the point, you can assume that no two points lie in a same coordinate and no three points lie in a same line. The coordinate of the point is in the range[-10086,10086].

    1 <= T <=100, 1 <= N <= 30

    Output

    For each case, output the case number first, and then output the number of different convex quadrilateral in the sky. Two convex quadrilaterals are considered different if they lie in the different position in the sky.

    Sample Input

    2
    4
    0 0
    100 0
    0 100
    100 100
    4
    0 0
    100 0
    0 100
    10 10

    Sample Output

    Case 1: 1
    Case 2: 0
     
    福州大学,福建省赛;ps:http://acm.fzu.edu.cn/problem.php?pid=2148
     
    题意;平面上给定N个点求不同的凸四边形个数;
     
    思路:凸四边形的对角线相交;关键是判断对角线相交问题,先连接两直线,然后另外的两点代入直线,得到s1,s2;
     
    s1*s2<0,表示在线段两侧,这里要用两次比较;即当a,b做线段时,判断点d,c是否在线段两端;当c,d做线段时,
     
    判断a,b是否在线段两端,这样是为了排除三个点共线的情况!
     
    详见代码:
    #include<stdio.h>
    #include<math.h>
    #include<string.h>
    #define MAX 35
    __int64 ans[MAX][2];
    
    int cheak(int i,int j,int k,int l)
    {
    
        __int64 x1,y1,x2,y2,x3,y3,x4,y4;
        x1=ans[i][0];
        y1=ans[i][1];
        x2=ans[j][0];
        y2=ans[j][1];
        x3=ans[k][0];
        y3=ans[k][1];
        x4=ans[l][0];
        y4=ans[l][1];
        double k1,k2,b1,b2,s1,s2,s3,s4;
        if(x2==x1&&x3==x4)
            return 0;
        if(x2==x1&&x3!=x4)
        {
            s1=x3-x1;
            s2=x4-x1;
            if(s1*s2>=0)
                return 0;
            else
            {
                k2=(y3-y4)*1.0/(x3-x4);
                b2=y3-k2*x3;
                s3=(y2-b2)-k2*x2;
                s4=(y1-b2)-k2*x1;
                if(s3*s4>=0)
                    return 0;
                if(s1*s2<0&&s3*s4<0)
                    return 1;
            }
            
        }
        if(x3==x4&&x1!=x2)
        {
            s3=x1-x3;
            s4=x2-x3;
            if(s3*s4>=0)
                return 0;
            else
            {
                k1=(y2-y1)*1.0/(x2-x1);
                b1=y1-k1*x1;
                s1=(y3-b1)-k1*x3;
                s2=(y4-b1)-k1*x4;
                if(s1*s2>=0)
                    return 0;        
                if(s1*s2<0&&s3*s4<0)
                    return 1;
            }
        }
        else
        {
            k1=(y2-y1)*1.0/(x2-x1);
            b1=y1-k1*x1;
            s1=(y3-b1)-k1*x3;
            s2=(y4-b1)-k1*x4;
            if(s1*s2>=0)
            {
                return 0;        
            }
            else
            {
                k2=(y3-y4)*1.0/(x3-x4);
                b2=y3-k2*x3;
                s3=(y2-b2)-k2*x2;
                s4=(y1-b2)-k2*x1;
                if(s3*s4>=0)
                    return 0;
                if(s1*s2<0&&s3*s4<0)
                    return 1;
            }
        }
    }
    
    
    int main()
    {
        int T,N;
        int i,j,k,l,cnt;
        scanf("%d",&T);
        for(cnt=1;cnt<=T;cnt++)
        {
            scanf("%d",&N);
            memset(ans,0,sizeof(ans));
            for(i=0;i<N;i++)
            {
                scanf("%I64d%I64d",&ans[i][0],&ans[i][1]);
            }
            int temp=0;
            for(i=0;i<N-3;i++)
                for(j=i+1;j<N-2;j++)
                    for(k=j+1;k<N-1;k++)
                        for(l=k+1;l<N;l++)
                        {
                            if(cheak(i,j,k,l))
                                temp++;
                            if(cheak(i,k,j,l))
                                temp++;
                            if(cheak(i,l,k,j))
                                temp++;
                        }
            printf("Case %d: %d
    ",cnt,temp);
    
        }
        return 0;
    }
    
    
    /*
    20
    4
    0 0
    100 0
    0 100
    100 100
    5
    0 0
    10 0
    0 5
    5 5
    15 0
    4
    0 0
    100 0
    0 100
    10 10
    5
    1 1
    5 6
    9 7
    5 5
    2 2
    4
    1 1
    1 1
    1 1
    1 1
    5
    1 1
    2 2
    3 3
    4 4
    5 5
    6
    5 8
    6 4
    1 0
    10 5
    8 6
    3 5
    
    */

       

        表示比赛的时候策略错误。。。应该让我自己做这题的,不过还是很感谢我给力的队友啊。。。    

    (虽然我是个小坑!              o(∩_∩)o 哈哈)那么我会好好努力的,大家一起加油哈!

  • 相关阅读:
    java_IO读写模版
    c#_DropdownList Panel Textbox 控件交互使用,有autopostback和没有的区别
    C#_datatable 写入大量数据_BulkCopy
    C#_datatable_读取
    C#_数据库交互_SqlHelper
    C#_数据库基本交互
    C#_Wpf_DataContex上下文整个类绑定
    C#_wpf_userinput_数据绑定_后台对象改变,界面数据也变化
    C#_delegate
    C#_delegate
  • 原文地址:https://www.cnblogs.com/yuyixingkong/p/3488034.html
Copyright © 2020-2023  润新知