HDU5533-计算几何|暴力-G
来源:互联网 发布:淘宝买家提取神器 编辑:程序博客网 时间:2024/05/22 15:15
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
- HDU5533-计算几何|暴力-G
- HDU5533 Dancing Stars on Me(计算几何)
- HDU5533 Dancing Stars on Me(计算几何)
- 17ICPC南宁 G I 计算几何+暴力
- HDU5533(水几何~)
- hdu3902计算几何。。暴力
- hdu 3952 计算几何 暴力
- FZU2148计算几何,暴力搜索
- HDU 5533(计算几何+暴力)
- HDU 4445(计算几何+暴力)
- hdu 6055 计算几何+暴力
- hdu5533 Dancing Stars on Me(几何水)
- 玲珑oj1143 计算几何你瞎暴力
- A 计算几何你瞎暴力
- 玲珑学院 1143 计算几何你瞎暴力【计算几何】【技巧暴力】
- 北京G,计算几何,线段相交
- “玲珑杯”ACM比赛 Round #18 A -- 计算几何你瞎暴力(计算几何)
- hdu 1077 Catching Fish 计算几何+暴力枚举
- Hive安装
- 解决MySql 数据库 提示:1045 access denied for user 'root'@'localhost' using password yes
- 命中注定
- shell编程之变量
- 暑假训练---prim--引水工程
- HDU5533-计算几何|暴力-G
- HDU6006-Engineer Assignment
- LeetCode-80. Remove Duplicates from Sorted Array II
- Bag of Words(BOW)模型
- 【成长之旅】2017上半年总结
- HDU1069——Monkey and Banana(动态规划)
- 最短路径算法
- seo知虎告诉您seo日常工作的重点是什么?
- Makefile 管理工具 — Automake and Autoconf