hdu 5533 Dancing Stars on Me 【2015ACM/ICPC亚洲区长春站-重现赛(感谢东北师大)】

Dancing Stars on Me

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 370    Accepted Submission(s): 222

Problem Description

The sky was brushed clean by the wind and the stars were cold in a black sky. What a wonderful night. You observed that, sometimes the stars can form a regular polygon in the sky if we connect them properly. You want to record these moments by your smart camera.
Of course, you cannot stay awake all night for capturing. So you decide to write a program running on the smart camera to check whether the stars can form a regular polygon and capture these moments automatically.

Formally, a regular polygon is a convex polygon whose angles are all equal and all its sides have the same length. The area of a regular polygon must be nonzero. We say the stars can form a regular polygon if they are exactly the vertices of some regular polygon.
To simplify the problem, we project the sky to a two-dimensional plane here, and you just need to check whether the stars can form a regular polygon in this plane.

 

Input

The first line contains a integer T indicating
the total number of test cases. Each test case begins with an integer n,
denoting the number of stars in the sky. Following n lines,
each contains 2 integers xi,yi,
describe the coordinates of n stars.

1≤T≤300
3≤n≤100
−10000≤xi,yi≤10000
All coordinates are distinct.

 

Output

For each test case, please output "`YES`" if the stars can form a regular polygon. Otherwise, output "`NO`" (both without quotes).

 

Sample Input


3
3
0 0
1 1
1 0
4
0 0
0 1
1 0
1 1
5
0 0
0 1
0 2
2 2
2 0

 

Sample Output


NO
YES
NO

 

题目大意:

就是判断给出的坐标是不是能够组成一个正 m 边形。。。

解题思路:

首先要知道,只有当 m == 4 的时候才有可能是正方形,别的都不可能(因为坐标是整数)。。。

所以只要判断是不是正方形就 ok 了, 可是给出的坐标不一定是按照顺序给出的,所以要判断一下,让他按照顺序给出。。。

上代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
#include <set>
using namespace std;

#define MM(a) memset(a,0,sizeof(a))

typedef long long LL;
typedef unsigned long long ULL;
const int maxn = 1e3+5;
const int mod = 1000000007;
const double eps = 1e-7;
LL gcd(LL a, LL b)
{
    if(b == 0)
        return a;
    return gcd(b, a%b);
}
struct node
{
    int x, y;
} arr[maxn];
int xx[maxn], yy[maxn];
bool cmp(node a, node b)
{
    if(a.y != b.y)
        return a.x < b.x;
    return a.y < a.y;
}

int main()
{
    int T, m;
    cin>>T;
    while(T--)
    {
        cin>>m;
        for(int i=0; i<m; i++)
            cin>>arr[i].x>>arr[i].y;
        if(m != 4)
            puts("NO");
        else
        {
            sort(arr, arr+4, cmp);
            if(arr[1].y < arr[0].y)
                swap(arr[1], arr[2]);
            swap(arr[2], arr[3]);
            /*for(int i=0; i<4; i++)
                cout<<arr[i].x<<" "<<arr[i].y<<endl;*/
            bool ok = false;
            for(int i=1; i<m; i++)
            {
                xx[i] = arr[i].x - arr[i-1].x;
                yy[i] = arr[i].y - arr[i-1].y;
            }
            xx[0] = arr[3].x - arr[0].x;
            yy[0] = arr[3].y - arr[0].y;
            int sum = 0;
            for(int i=1; i<m; i++)
            {
                if((xx[i]*xx[i]+yy[i]*yy[i]) == (xx[i-1]*xx[i-1]+yy[i-1]*yy[i-1]))
                    sum++;
            }
            if(xx[0]*xx[1] + yy[0]*yy[1] == 0)
                ok = true;
            if(sum==3 && ok)
                puts("YES");
            else
                puts("NO");
        }
    }
    return 0;
}
/**
4
0 1
1 0
2 1
1 2
**/
时间: 2024-09-08 03:21:33

hdu 5533 Dancing Stars on Me 【2015ACM/ICPC亚洲区长春站-重现赛(感谢东北师大)】的相关文章

hdu 5131 Song Jiang&amp;#39;s rank list 【2014ACM/ICPC亚洲区广州站-重现赛】

Song Jiang's rank list Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 512000/512000 K (Java/Others) Total Submission(s): 966    Accepted Submission(s): 502 Problem Description <Shui Hu Zhuan>,also <Water Margin>was written by Shi Nai'

HDU4802-GPA

GPA Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 814    Accepted Submission(s): 530 Problem Description In college, a student may take several courses. for each course i, he earns a certain

《OOD启思录》目录—导读

版权声明OOD启思录Authorized translation from the English language edition, entitled OBJECT-ORIENTED DESIGN HEURISTICS (PAPERBACK), 1E, 9780321774965 by RIEL, ARTHUR J., published by Pearson Education, Inc, publishing as Addison-Wesley Professional, Copyrigh

hdu 5491 The Next(ICPC合肥赛)

The Next Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 808    Accepted Submission(s): 316 Problem Description Let L denote the number of 1s in integer D's binary representation. Given two int

hdu 2642 Stars

点击打开hdu 2642 思路: 二维树状数组 分析: 裸题 代码:   /************************************************ * By: chenguolin * * Date: 2013-08-21 * * Address: http://blog.csdn.net/chenguolinblog * ***********************************************/ #include<cstdio> #includ

hdu 5461 Largest Point (2015 ACM/ICPC Asia Regional Shenyang Online)

点击打开链接 Largest Point Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total Submission(s): 474    Accepted Submission(s): 213 Problem Description Given the sequence A with n integers t1,t2,⋯,tn. Given the integral c

HDOJ(HDU) 2309 ICPC Score Totalizer Software(求平均值)

Problem Description The International Clown and Pierrot Competition (ICPC), is one of the most distinguished and also the most popular events on earth in the show business. One of the unique features of this contest is the great number of judges that

hdu 5455 Fang Fang(2015 ACM/ICPC Asia Regional Shenyang Online)

点击打开链接 Fang Fang Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total Submission(s): 531    Accepted Submission(s): 232 Problem Description Fang Fang says she wants to be remembered. I promise her. We define the s

算法:HDU 4681 String (dp, LCS | 多校8)

题意 给出3个字符串A,B,C,要你找一个字符串D, 要满足下面规定 a) D是A的子序列 b) D是B 的子序列 c) C是D的子串 求D的最大长度 要注意子序列和子串的区别,子序列是不连续的,字串是连 续的 思路 由题目可知,C一定是A和B的子序列,那么先假设C在A和B中只有一个子序列,看下 面例子: abcdefdeg acebdfgh cf 可以看到"cf"在A串的[3, 6]区间 内, 在B串的[2,6]区间(黄色背景) 因为所求的C是D的子串,所以在该黄色区间内的其他字母一