2015长春 HDU 5531 Rebuild

题意:n个顶点组成的多边形能否形成正多边形?

  1 #include <cstdio>
  2 #include <cstring>
  3 #include <cmath>
  4 #include <cstdlib>
  5 #include <iostream>
  6 #include <algorithm>
  7 #include <queue>
  8 #include <map>
  9 #include <vector>
 10 using namespace std;
 11 const int maxn=111;
 12 const int maxnode=4000010;
 13 typedef long long LL;
 14 struct Point
 15 {
 16     int x,y;
 17     Point (int x=0,int y=0):x(x),y(y) {}
 18
 19 } p[maxn];
 20 typedef Point Vector;
 21 Vector operator+(Vector A,Vector B)
 22 {
 23     return Vector(A.x+B.x,A.y+B.y);
 24 }
 25
 26 Vector operator-(Point A,Point B)
 27 {
 28     return Vector(A.x-B.x,A.y-B.y);
 29 }
 30 Vector operator*(Vector A,int p)
 31 {
 32     return Vector(A.x*p,A.y*p);
 33 }
 34
 35 Vector operator /(Vector A,int p)
 36 {
 37     return Vector(A.x/p,A.y/p);
 38 }
 39
 40 bool operator <(const Point&a,const Point &b)
 41 {
 42     return a.x<b.x||(a.x==b.x&&a.y<b.y);
 43 }
 44
 45 int Cross(Vector A,Vector B)
 46 {
 47     return A.x*B.y-A.y*B.x;
 48 }
 49
 50 int ConvexHull(Point *p,int n,Point *ch)
 51 {
 52     sort(p,p+n);
 53     int m=0;
 54     for(int i=0; i<n; i++)
 55     {
 56         while(m>1&&Cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])<=0)
 57             m--;
 58         ch[m++]=p[i];
 59     }
 60     int k=m;
 61     for(int i=n-2; i>=0; i--)
 62     {
 63         while(m>k&&Cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])<=0)m--;
 64         ch[m++]=p[i];
 65     }
 66     if(n>1)
 67         m--;
 68     return m;
 69 }
 70 int n;
 71 Point ans[maxn];
 72 LL  dis(LL X1,LL Y1,LL X2,LL Y2)
 73 {
 74     return (X1-X2)*(X1-X2)+(Y1-Y2)*(Y1-Y2);
 75 }
 76 int main()
 77 {
 78     freopen("in.txt","r",stdin);
 79     int t ;
 80     scanf("%d",&t);
 81     while(t--)
 82     {
 83         scanf("%d",&n);
 84         for(int i=0; i<n; i++)
 85             scanf("%d%d",&p[i].x,&p[i].y);
 86         int m=ConvexHull(p,n,ans);
 87         if(m!=n)
 88         {
 89             printf("NO\n");
 90             continue;
 91         }
 92         bool flag=true;
 93         LL len=dis(ans[0].x,ans[0].y,ans[m-1].x,ans[m-1].y);
 94
 95         for(int i=1; i<m; i++)
 96         {
 97             if(len!=dis(ans[i].x,ans[i].y,ans[i-1].x,ans[i-1].y))
 98             {
 99                 flag=false;
100                 break;
101             }
102         }
103         if(flag)printf("YES\n");
104         else printf("NO\n");
105
106     }
107     return 0;
108 }

时间: 2024-12-21 21:37:06

2015长春 HDU 5531 Rebuild的相关文章

2015ACM/ICPC亚洲区长春站 E hdu 5531 Rebuild

Rebuild Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 446    Accepted Submission(s): 113 Problem Description Archaeologists find ruins of Ancient ACM Civilization, and they want to rebuild i

HDU 4791 Rebuild (2015长春现场赛,计算几何+三分)

Rebuild Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 521    Accepted Submission(s): 125 Problem Description Archaeologists find ruins of Ancient ACM Civilization, and they want to rebuild i

hdu 5441 Travel (2015长春网赛)

http://acm.hdu.edu.cn/showproblem.php?pid=5441 题目大意是给一个n个城市(点)m条路线(边)的双向的路线图,每条路线有时间值(带权图),然后q个询问,每个询问一个时间值 求不大于这个时间的可以连通的城市有多少种连法 比如样例中第一个询问6000,不大于6000时间值的连通城市有3,5.所以有3-->5,5-->3两种 第二个询问10000,符合条件的连通的城市有2,3,5,所以有2-->3,3-->2,2-->5,5-->2

Hdu 5439 Aggregated Counting (2015长春网络赛 ACM/ICPC Asia Regional Changchun Online 找规律)

题目链接: Hdu 5439 Aggregated Counting 题目描述: 刚开始给一个1,序列a是由a[i]个i组成,最后1就变成了1,2,2,3,3,4,4,4,5,5,5.......,最后问a[i]==n(i最大)时候,i最后一次出现的下标是多少? 解题思路: 问题可以转化为求a[i] == n (i最大),数列前i项的和为多少. index: 1 2 3 4 5 6 7 8 9 10 a:        1 2 2 3 3 4 4 4 5 5 可以观察出:ans[1] = 1,

Hdu 5445 Food Problem (2015长春网络赛 ACM/ICPC Asia Regional Changchun Online)

题目链接: Hdu  5445 Food Problem 题目描述: 有n种甜点,每种都有三个属性(能量,空间,数目),有m辆卡车,每种都有是三个属性(空间,花费,数目).问至少运输p能量的甜点,花费最小是多少? 解题思路: 明显可以看出是多重背包搞两次,但是数据范围太大了,背包要到2*1e6,感觉会TLe.还是呆呆的写了一发,果断超啊!然后滚回去看背包九讲课件了,看到了二进制压缩的时候,感觉可以搞这个题目.试了一下果然AC,原本物品数目是100*100,二进制压缩以后也就是100*log210

Travel(HDU 5441 2015长春区域赛 带权并查集)

Travel Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 2404    Accepted Submission(s): 842 Problem Description Jack likes to travel around the world, but he doesn’t like to wait. Now, he is tr

hdu 5441 (2015长春网络赛E题 带权并查集 )

n个结点,m条边,权值是 从u到v所花的时间 ,每次询问会给一个时间,权值比 询问值小的边就可以走 从u到v 和从v到u算不同的两次 输出有多少种不同的走法(大概是这个意思吧)先把边的权值 从小到大排序 询问值也按从小到大排序num记录集合里元素的个数每合并两个集合 ans增加 2*num[u]*num[v] Sample Input15 5 3 //n w q2 3 63341 5 157243 5 57054 3 123821 3 2172660001000013000 Sample Out

ACM学习历程—HDU 5443 The Water Problem(RMQ)(2015长春网赛1007题)

Problem Description In Land waterless, water is a very limited resource. People always fight for the biggest source of water. Given a sequence of water sources with a1,a2,a3,...,an representing the size of the water source. Given a set of queries eac

ACM学习历程—HDU 5446 Unknown Treasure(数论)(2015长春网赛1010题)

Problem Description On the way to the next secret treasure hiding place, the mathematician discovered a cave unknown to the map. The mathematician entered the cave because it is there. Somewhere deep in the cave, she found a treasure chest with a com