HDU5533-计算几何|暴力-G - Dancing Stars on Me

http://acm.hdu.edu.cn/showproblem.php?pid=5533
给定你一些点,问你能否构成正多边形。
因为出入的是int类型,所以只能是 正四边形。
1 找出所有点之间的最短距离,即边长。然后再在所有点中找出与边长相等的,只要数量为n即
说明能够成正多边形
2 要求输入的为整数,所以只有正四边形才能成立。
或者求一下 凸包 搞一搞

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm>
using namespace std;
/*
*/
const int maxn=200;
vector<double >v;
double  a[maxn];
double  b[maxn];
int main()
{   int t;
    int m;
    scanf("%d",&t);
    while(t--){
          v.clear();
          scanf("%d",&m);
          for(int i=1;i<=m;i++){
              scanf("%lf%lf",&a[i],&b[i]);
          }
          for(int i=1;i<=m;i++){
              for(int j=i+1;j<=m;j++){
                  v.push_back(1ll*(a[i]-a[j])*(a[i]-a[j])+(b[i]-b[j])*(b[i]-b[j]));
              }
          }
          sort(v.begin(),v.end());
          if(v[0]==v[m-1])
            puts("YES");
          else
            {puts("NO");}
    }
    return 0;
}

凸包

#include <map>
#include <set>
#include <vector>
#include <math.h>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <functional>
const double pi = acos(-1.0);
using namespace std;
const int MAXN=10005;
const double eps=1e-2;
int dcmp(double x){
    if(fabs(x)<eps)return 0;
    if(x>0)return 1;
    return -1;
}                                                   //弄精度
struct Point {
    double x,y;
}p[MAXN];                                           //搞点
double dot(Point a,Point b,Point c){
    double s1=b.x-a.x;
    double t1=b.y-a.y;
    double s2=c.x-a.x;
    double t2=c.y-a.y;
    return s1*s2+t1*t2;
}                                                     //点积
int n,res[MAXN],top;//全局变量,n是给出点的个数,top是凸包顶点的个数,res[]存排序后凸包上点的下标
bool cmp(Point a,Point b){
    if(a.y==b.y)return a.x<b.x;
    return a.y<b.y;
}
bool mult(Point sp,Point ep,Point op){
    return (sp.x-op.x)*(ep.y-op.y)>=(ep.x-op.x)*(sp.y-op.y);
}
void Graham(){
    int len;
    top=1;
    sort(p,p+n,cmp);
    if(n==0)return;res[0]=0;
    if(n==1)return;res[1]=1;
    if(n==2)return;res[2]=2;
    for(int i=2;i<n;i++){
        while(top&&mult(p[i],p[res[top]],p[res[top-1]]))top--;
        res[++top]=i;
    }
    len=top;
    res[++top]=n-2;
    for(int i=n-3;i>=0;i--){
        while(top!=len&&mult(p[i],p[res[top]],p[res[top-1]]))top--;
        res[++top]=i;
    }
}                                                               //求凸包
 double dist(Point a,Point b){
    return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
int main()
{
    int m,t;
    cin>>t;
    while(t--)
        {
            cin>>m;
            n=m;
        for(int i=0;i<m;i++)
            scanf("%lf%lf",&p[i].x,&p[i].y);
        Graham();
        if(top!=m){cout<<"NO\n";continue;}
        double dis=dist(p[res[0]],p[res[1]]);
        int f=0;
        for(int i=0;i<top;i++)
            if(dist(p[res[i]],p[res[i+1]])!=dis)
            {
                f=1;break;
            }
            if(f==0)
        cout<<"YES\n";
        else cout<<"NO\n";
}
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值