标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 186 Accepted Submission(s): 124
1 #include <cstdio> 2 #include <cstring> 3 #include <cstdlib> 4 #include <cmath> 5 #include <ctime> 6 #include <iostream> 7 #include <map> 8 #include <set> 9 #include <algorithm> 10 #include <vector> 11 #include <deque> 12 #include <queue> 13 #include <stack> 14 using namespace std; 15 typedef long long LL; 16 typedef double DB; 17 #define MIT (2147483647) 18 #define MLL (1000000000000000001LL) 19 #define INF (1000000001) 20 #define For(i, s, t) for(int i = (s); i <= (t); i ++) 21 #define Ford(i, s, t) for(int i = (s); i >= (t); i --) 22 #define Rep(i, n) for(int i = (0); i < (n); i ++) 23 #define Repn(i, n) for(int i = (n)-1; i >= (0); i --) 24 #define mk make_pair 25 #define ft first 26 #define sd second 27 #define puf push_front 28 #define pub push_back 29 #define pof pop_front 30 #define pob pop_back 31 #define sz(x) ((int) (x).size()) 32 inline void SetIO(string Name) 33 { 34 string Input = Name + ".in"; 35 string Output = Name + ".out"; 36 freopen(Input.c_str(), "r", stdin); 37 freopen(Output.c_str(), "w", stdout); 38 } 39 40 inline int Getint() 41 { 42 char ch = ‘ ‘; 43 int Ret = 0; 44 bool Flag = 0; 45 while(!(ch >= ‘0‘ && ch <= ‘9‘)) 46 { 47 if(ch == ‘-‘) Flag ^= 1; 48 ch = getchar(); 49 } 50 while(ch >= ‘0‘ && ch <= ‘9‘) 51 { 52 Ret = Ret * 10 + ch - ‘0‘; 53 ch = getchar(); 54 } 55 return Flag ? -Ret : Ret; 56 } 57 58 const int N = 110; 59 struct Point 60 { 61 int x, y; 62 } Arr[N]; 63 int n; 64 65 inline void Solve(); 66 67 inline void Input() 68 { 69 int TestNumber = Getint(); 70 while(TestNumber--) 71 { 72 n = Getint(); 73 For(i, 1, n) 74 { 75 Arr[i].x = Getint(); 76 Arr[i].y = Getint(); 77 } 78 Solve(); 79 } 80 } 81 82 inline LL Sqr(int x) { 83 return 1LL * x * x; 84 } 85 86 inline int Multi(const Point &O, const Point &A, const Point &B) 87 { 88 int X1 = A.x - O.x, X2 = B.x - O.x, Y1 = A.y - O.y, Y2 = B.y - O.y; 89 return X1 * Y2 - X2 * Y1; 90 } 91 92 inline LL GetDist(const Point &A, const Point &B) 93 { 94 return Sqr(B.x - A.x) + Sqr(B.y - A.y); 95 } 96 97 inline bool Compare(const Point &A, const Point &B) 98 { 99 int Det = Multi(Arr[1], A, B); 100 if(Det) return Det > 0; 101 LL Dist1 = GetDist(Arr[1], A), Dist2 = GetDist(Arr[1], B); 102 return Dist1 < Dist2; 103 } 104 105 inline void Solve() 106 { 107 For(i, 2, n) 108 if(Arr[i].x < Arr[1].x || (Arr[i].x == Arr[1].x && Arr[i].y < Arr[1].y)) 109 swap(Arr[i], Arr[1]); 110 sort(Arr + 2, Arr + 1 + n, Compare); 111 112 Arr[n + 1] = Arr[1], Arr[n + 2] = Arr[2]; 113 bool Flag = 0; 114 int Tmp, Dist; 115 For(i, 1, n) 116 { 117 int Det = Multi(Arr[i], Arr[i + 1], Arr[i + 2]); 118 LL Dist1 = GetDist(Arr[i], Arr[i + 1]); 119 LL Dist2 = GetDist(Arr[i + 1], Arr[i + 2]); 120 if(Det <= 0 || Dist1 != Dist2) 121 { 122 puts("NO"); 123 return ; 124 } 125 if(Flag) 126 { 127 if(Tmp != Det || Dist1 != Dist) 128 { 129 puts("NO"); 130 return ; 131 } 132 } 133 else Flag = 1, Tmp = Det, Dist = Dist1; 134 } 135 puts("YES"); 136 } 137 138 int main() 139 { 140 Input(); 141 //Solve(); 142 return 0; 143 }
2015ACM/ICPC亚洲区长春站 G hdu 5533 Dancing Stars on Me
标签:
原文地址:http://www.cnblogs.com/StupidBoy/p/4937250.html