zoukankan      html  css  js  c++  java
  • Dancing Stars on Me(判断正多边形)

    Dancing Stars on Me

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

    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.
    1T300 3n100 10000xi,yi10000 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
     

    题意:给你一个多边形,问你这个多边形是否是正多边形。。。

    题解:无奈啊,我刚开始就判断边是否相等,用差集排序,相邻判断,果断wa,又想着没考虑角度,就想着对相邻两个边求差集,是否相等,各种wa,无耐加心碎啊,然后就暴力了了。。。就判断个相等边都要大于等于2,然后就对了。。。fuck。。。

    代码:

    #include<iostream>
    #include<cstring>
    #include<cstdio>
    #include<cmath>
    #include<vector>
    #include<map>
    #include<algorithm>
    using namespace std;
    #define mem(x,y) memset(x,y,sizeof(x))
    #define SI(x) scanf("%d",&x)
    #define SL(x) scanf("%lld",&x)
    #define PI(x) printf("%d",x)
    #define PL(x) printf("%lld",x)
    #define P_ printf(" ")
    #define T_T while(T--)
    typedef long long LL;
    const int INF=0x3f3f3f3f;
    const int MAXN=210;
    int N;
    struct Node{
    	LL x,y;
    	/*Node(LL x=0,LL y=0):x(x),y(y){}*/
    };
    Node dt[MAXN];
    /*LL cross(Node a,Node b){
    	return a.x*b.y-a.y*b.x;
    }
    
    int cmp(Node a,Node b){
    	if(cross(a,b)>=0)return 1;
    	else return 0;
    }*/
    /*
    Node operator - (Node a,Node b){
    	return Node(a.x-b.x,a.y-b.y);
    }*/
    double getl(Node a,Node b){
    	LL x=a.x-b.x,y=a.y-b.y;
    	return sqrt(1.0*x*x+1.0*y*y);
    }
    bool judge(){
    	//double temp=getl(dt[0],dt[N-1]);
    	double ans;
    	for(int i=0;i<N;i++){
    	//	if(temp!=getl(dt[i],dt[i-1]))return false;
    	double temp=INF;
    	int cnt=0;
    	for(int j=0;j<N;j++){
    			if(i==j)continue;
    			if(getl(dt[i],dt[j])<temp)temp=getl(dt[i],dt[j]);
    			if(i&&ans==temp)cnt++;
    		}
    		if(!i)ans=temp;
    		//printf("%lf %d
    ",ans,cnt);
    		if(i)if(temp!=ans||cnt<2)return false;
    	}
    	
    	/*double x=cross(dt[0]-dt[N-1],dt[0]-dt[1]);
    	for(int i=1;i<N-1;i++){
    		int y;
    		if(x!=(y=cross(dt[i]-dt[i-1],dt[i]-dt[i+1]))){
    			return false;
    		}
    	}
    	if(x!=cross(dt[N-1]-dt[N-2],dt[N-1]-dt[0]))return false;*/
    	return true;
    }
    int main(){
    	int T;
    	SI(T);
    	T_T{
    		SI(N);
    		for(int i=0;i<N;i++)SL(dt[i].x),SL(dt[i].y);
    		//sort(dt,dt+N,cmp);
    		//for(int i=1;i<N;i++)printf("%d
    ",cross(dt[i],dt[i-1]));
    		if(judge())puts("YES");
    		else puts("NO");
    	}
    	return 0;
    }
    

      

  • 相关阅读:
    简单网络问题排查记录一
    安装mysql_sniffer报错undefined reference to symbol 'pthread_setspecific@@GLIBC_2.2.5'问题
    tengine安装ngx_http_lua_module
    Django——URL详解/Django中URL是如何与urls文件匹配的
    Python学习——enumerate
    Python学习——装饰器/decorator/语法糖
    缓存优化
    页面重绘 回流及其优化
    window.getComputedStyle()方法的使用及其扩展
    java 三个循环的优缺点
  • 原文地址:https://www.cnblogs.com/handsomecui/p/5023628.html
Copyright © 2011-2022 走看看