标签:多校 ble abs ref cep cin cout ring ret
http://acm.hdu.edu.cn/showproblem.php?pid=6055
【题意】
给定n个格点,问有多少个正多边形
【思路】
【Accepted】
1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 #include <cmath> 5 #include<iostream> 6 #include <vector> 7 using namespace std ; 8 #define eqs 1e-9 9 struct node 10 { 11 double x , y ; 12 } p[1100] ; 13 bool cmp(node a,node b) 14 { 15 return ( a.x < b.x || ( a.x == b.x && a.y < b.y ) ) ; 16 } 17 bool judge(double x,double y,int n) 18 { 19 int low = 0 , mid , high = n-1 ; 20 while( low <= high ) 21 { 22 mid = (low + high) / 2 ; 23 if( fabs(p[mid].x-x) < eqs && fabs(p[mid].y-y) < eqs ) 24 return true ; 25 else if( p[mid].x-x > eqs || ( fabs(p[mid].x-x) < eqs && p[mid].y-y > eqs ) ) 26 high = mid - 1 ; 27 else 28 low = mid + 1 ; 29 } 30 return false ; 31 } 32 int main() 33 { 34 int n,num; 35 double x,xx,y,yy; 36 while(scanf("%d", &n)!=EOF&&n) 37 { 38 num = 0 ; 39 for(int i = 0 ; i < n ; i++) 40 { 41 cin>>p[i].x>>p[i].y; 42 } 43 sort(p,p+n,cmp) ; 44 for(int i = 0 ; i < n ; i++) 45 { 46 for(int j = i+1 ; j < n ; j++) 47 { 48 if( i == j ) continue ; 49 x = (p[i].x+p[j].x)/2 ; 50 y = (p[i].y+p[j].y)/2 ; 51 xx = p[i].x - x ; 52 yy = p[i].y - y ; 53 if( judge(x+yy,y-xx,n) && judge(x-yy,y+xx,n) ) 54 { 55 num++ ; 56 } 57 } 58 } 59 cout<<num/2<<endl; 60 } 61 return 0; 62 }
【2017多校训练2+计算几何+板】HDU 6055 Regular polygon
标签:多校 ble abs ref cep cin cout ring ret
原文地址:http://www.cnblogs.com/itcsl/p/7253078.html