Dancing Stars on Me

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

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
 
Source
 
Recommend
hujie   |   We have carefully selected several similar problems for you:       
题意:给你n个点(-1e4<x,y<=1e4),判断这n个点能否组成一个正n边形;
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <set>
#define MM(a) memset(a,0,sizeof(a))
typedef long long ll;
typedef unsigned long long ULL;
const double eps = 1e-12;
const int inf = 0x3f3f3f3f;
const double pi=acos(-1);
using namespace std; struct Point{
int x,y;
void read()
{
scanf("%d%d",&x,&y);
}
}p[105],tubao[105]; int dcmp(double a)
{
if(fabs(a)<eps) return 0;
else if(a>0) return 1;
else return -1;
} Point operator-(Point a,Point b)
{
return (Point){a.x-b.x,a.y-b.y};
} double dis(Point a)
{
return sqrt(a.x*a.x+a.y*a.y);
} double cross(Point a,Point b)
{
return a.x*b.y-b.x*a.y;
} double dot(Point a,Point b)
{
return a.x*b.x+a.y*b.y;
} bool cmp(Point a,Point b)
{
if(a.x!=b.x) return a.x<b.x;
else return a.y<b.y;
} int convex_hull(Point *p,int n,Point *tubao)
{
sort(p+1,p+n+1,cmp);
int m=0;
for(int i=1;i<=n;i++)
{
while(m>=2&&cross(p[i]-tubao[m-1],tubao[m]-tubao[m-1])>0) m--;
tubao[++m]=p[i];
}
int k=m;
for(int i=n-1;i>=1;i--)
{
while(m-k>=1&&cross(p[i]-tubao[m-1],tubao[m]-tubao[m-1])>0) m--;
tubao[++m]=p[i];
}
m--;
return m;
} int main()
{
int cas,n;
scanf("%d",&cas);
while(cas--)
{
scanf("%d",&n);
for(int i=1;i<=n;i++) p[i].read();
int k=convex_hull(p,n,tubao);
tubao[k+1]=tubao[1]; bool flag=true;
double tmp=(n-2.0)*pi/n; for(int i=1;i<=k-1;i++)
{
Point a=tubao[i+1]-tubao[i],b=tubao[i+2]-tubao[i+1];
double cosang=dot(a,b)/(dis(a)*dis(b));
double ang=acos(cosang);
ang=pi-ang;
if(dcmp(ang-tmp)!=0) {flag=false;break;}
}
if(flag) printf("YES\n");
else printf("NO\n");
}
return 0;
}

  分析:主要是借助这道题来分下下计算几何的精度问题,

double型数据精度处理的两种方式

1.相除改为ong long相乘,这种是肯定对的,不会错。

2.dcmp函数,这种比较简单,但是有一定的精度条件,如果角度是1/999999-1/1000000,那么相减起来就是1e-6*1/999999为1e-12级别,这样是可以使用dcmp的,比如本道题,因为1-e4<=x<=1e4,那么最小的角度差是1/(2*1e4-1)-1/2*1e4(最小的角是1/2*1e4,第二小的角度是1/(2*1e4-1))为1e-8级别>1e-12级别,所以可以用dcmp(eps<1e-12)

 

hdu 5533 正n边形判断 精度处理的更多相关文章

  1. HDU - 1317 ~ SPFA正权回路的判断

    题意:有最多一百个房间,房间之间连通,到达另一个房间会消耗能量值或者增加能量值,求是否能从一号房间到达n号房间. 看数据,有定5个房间,下面有5行,第 iii 行代表 iii 号 房间的信息,第一个数 ...

  2. hdu 5533 Dancing Stars on Me

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5533 Dancing Stars on Me Time Limit: 2000/1000 MS (Ja ...

  3. hdu 5533 Dancing Stars on Me(数学,水)

    Problem Description The sky was brushed clean by the wind and the stars were cold in a black sky. Wh ...

  4. HDU 5533/ 2015长春区域 G.Dancing Stars on Me 暴力

    Dancing Stars on Me Problem Description The sky was brushed clean by the wind and the stars were col ...

  5. HDU 5533 Dancing Stars on Me( 有趣的计算几何 )

    链接:传送门 题意:给出 n 个点,判断能不能构成一个正 n 边形,这 n 个点坐标是整数 思路:这道题关键就在与这 n 个点坐标是正整数!!!可以简单的分析,如果 n != 4,那一定就不能构成正 ...

  6. TZOJ 2392 Bounding box(正n边形三点求最小矩形覆盖面积)

    描述 The Archeologists of the Current Millenium (ACM) now and then discover ancient artifacts located ...

  7. Android 正 N 边形圆角头像的实现

    卖一下广告,欢迎大家关注我的微信公众号,扫一扫下方二维码或搜索微信号 stormjun94(徐公码字),即可关注. 目前专注于 Android 开发,主要分享 Android开发相关知识和一些相关的优 ...

  8. hdu 5533 Dancing Stars on Me 水题

    Dancing Stars on Me Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.p ...

  9. HDU 3342 Legal or Not(判断是否存在环)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3342 Legal or Not Time Limit: 2000/1000 MS (Java/Othe ...

随机推荐

  1. Nginx支持WebSocket服务

    server{ listen ; access_log logs/.jieyun.top.log main; server_name .jieyun.top; #绑定域名 index index.ph ...

  2. Python的argparse模块的使用

    Python的argparse模块的使用 最近看到一份Pytorch代码有以下内容: # Training settings parser = argparse.ArgumentParser(desc ...

  3. C++:函数先声明后实现

    贼神奇的是,直到昨天在写flex规则的时候我才知道C++中的函数要么在使用之前先定义,要么将实现放在调用之前,不允许先调用后实现.之前一年多竟然不知道这件事,汗````,当然也是可能这件事本身和我思考 ...

  4. 10 select、poll以及epoll

    IO复用:为了解释这个名词,首先来理解下复用这个概念,复用也就是共用的意思,这样理解还是有些抽象,为此,咱们来理解下复用在通信领域的使用, 在通信领域中为了充分利用网络连接的物理介质,往往在同一条网络 ...

  5. 帝国cms 加载更多的实现(父栏目以及子栏目都可以实现)

    1. <div class="pagelist"> <span id="loadmore" class="btn" sty ...

  6. tp中的u方法

    个人总结以免忘记 在模板中的使用{:U('地址', '参数'…)} <!--在模板中使用U方法 --> <a href="{:U('News/index')}" ...

  7. css强制换行显示省略号之显示两行后显示省略号

    1,首先来一个固定宽度,在一行显示,超出隐藏,显示省略号的样式 display:block; white-space:nowrap; overflow:hidden; text-overflow:el ...

  8. latex中文环境配置(针对北大模板,开题报告+中期答辩+毕业论文)

    最近自己在忙着开题,中文环境真的是emm 以下只针对北大的毕业论文模板,至于其他的中文环境没有尝试 主要是用不同的latex编辑器会报不同的错误,当然我最后还是统一成了pdflatex,经过无数次尝试 ...

  9. 币种大写算法(js)

    注意事项:小数精度处理问题,n*10出现精度误差,如1.88*10计算得18.799999999999997,实际想要的数据是18.8: 思路一:小数变成整数(通过字符串处理),计算后,变成小数: 思 ...

  10. C++虚函数和纯虚函数的用法和区别

    C++虚函数与纯虚函数用法与区别(转)   1. 虚函数和纯虚函数可以定义在同一个类(class)中,含有纯虚函数的类被称为抽象类(abstract class),而只含有虚函数的类(class)不能 ...