zoukankan      html  css  js  c++  java
  • hdu 5365 计算几何 给几个点判断是否为正方形




    Run

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)


    Problem Description
    AFA is a girl who like runing.Today,he download an app about runing .The app can record the trace of her runing.AFA will start runing in the park.There are many chairs in the park,and AFA will start his runing in a chair and end in this chair.Between two chairs,she running in a line.she want the the trace can be a regular triangle or a square or a regular pentagon or a regular hexagon.
    Please tell her how many ways can her find.
    Two ways are same if the set of chair that they contains are same.
     

    Input
    There are multiply case.
    In each case,there is a integer n(1 < = n < = 20)in a line.
    In next n lines,there are two integers xi,yi(0 < = xi,yi < 9) in each line.
     

    Output
    Output the number of ways.
     

    Sample Input
    4 0 0 0 1 1 0 1 1
     

    Sample Output
    1



    最后题目意思就是给你一系列点,问能组成正三角形,正四边形,正五边形,正六边形的个数(如果使用的点相同,则视为一种),实际上由于正三角形正五边形,正六边形不可能都由整数点(即横坐标和纵坐标都是整数)构成,故我们只用判断能组成多少个正方形即可。


    #include<stdio.h>
    #include<string.h>
    #include<stdlib.h>
    #include<queue>
    #include<stack>
    #include<math.h>
    #include<vector>
    #include<map>
    #include<set>
    #include<stdlib.h>
    #include<cmath>
    #include<string>
    #include<algorithm>
    #include<iostream>
    using namespace std;
    struct point
    {
        int  x,y;
    } pp[110];
    int s[6];
    bool judge(int a,int b,int c,int d)
    {
        int cnt=0;
        s[cnt++]=(pp[b].x-pp[a].x)*(pp[b].x-pp[a].x)+(pp[b].y-pp[a].y)*(pp[b].y-pp[a].y);
        s[cnt++]=(pp[c].x-pp[a].x)*(pp[c].x-pp[a].x)+(pp[c].y-pp[a].y)*(pp[c].y-pp[a].y);
        s[cnt++]=(pp[d].x-pp[a].x)*(pp[d].x-pp[a].x)+(pp[d].y-pp[a].y)*(pp[d].y-pp[a].y);
        s[cnt++]=(pp[c].x-pp[b].x)*(pp[c].x-pp[b].x)+(pp[c].y-pp[b].y)*(pp[c].y-pp[b].y);
        s[cnt++]=(pp[d].x-pp[b].x)*(pp[d].x-pp[b].x)+(pp[d].y-pp[b].y)*(pp[d].y-pp[b].y);
        s[cnt++]=(pp[d].x-pp[c].x)*(pp[d].x-pp[c].x)+(pp[d].y-pp[c].y)*(pp[d].y-pp[c].y);
        sort(s,s+6);//以上代码就是在求这四个点构成的边的长度,如果是正方形,那么排序后前四个大小一样,最后后两个大小一样
        if(s[0]==s[1]&&s[2]==s[1]&&s[2]==s[3]&&s[4]==s[5]&&s[4]!=s[3])return true;
        return false;
    
    }
    int main()
    {
        int  t,i,j,n,k,l,cnt;
        while(scanf("%d",&n)!=EOF)
        {
    
    
            cnt=0;
            for(i=0; i<n; i++)
                scanf("%d%d",&pp[i].x,&pp[i].y);
            for(i=0; i<n; i++)
                for(j=i+1; j<n; j++)
                    for(k=j+1; k<n; k++)
                        for(l=k+1; l<n; l++)
                            if(judge(i,j,k,l))cnt++;
    
           printf("%d
    ",cnt);
    
        }
        return 0;
    }
    




  • 相关阅读:
    [RN] React Native 使用 react-native-camera 过程中报错 Found react-native-camera 'mlkit' but wasn't required.`
    [RN] React Native 拍照、从相册选择、录像的实现
    10月14日站立会议
    第四周PSP &进度条
    课堂站立会议学习
    10月13号站立会议
    10月12号站立会议
    10月11号站立会议
    10月10号站立会议
    10月9号站立会议
  • 原文地址:https://www.cnblogs.com/hjch0708/p/7554829.html
Copyright © 2011-2022 走看看