Codeforces Round #502 (in memory of Leopoldo Taravilse, Div. 1 + Div. 2) E. The Supersonic Rocket
2018-08-13 23:14
393 查看
这道题比赛之后被重新加了几个case,很多人现在都过不了了
算法就是先求凸包,然后判断两个凸包相等
我们可以吧凸包序列化为两点距离和角度
角度如果直接拿向量的叉积是不对的,,因为钝角和锐角的叉积有可能相同。我直接把点积和叉积加一起当作角度其实也不严谨,,最好是变成三个元素,长度,叉积,点积
代码有所参考
算法就是先求凸包,然后判断两个凸包相等
我们可以吧凸包序列化为两点距离和角度
角度如果直接拿向量的叉积是不对的,,因为钝角和锐角的叉积有可能相同。我直接把点积和叉积加一起当作角度其实也不严谨,,最好是变成三个元素,长度,叉积,点积
代码有所参考
#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <climits> #include <cstring> #include <string> #include <vector> #include <list> #include <queue> #include <stack> #include <map> #include <set> #include <bitset> #include <algorithm> #include <functional> #include <iomanip> using namespace std; #define LL long long const int maxn = 100000 + 100; struct Point { LL x, y; Point() {} Point(LL xx, LL yy) { x = xx; y = yy; } }; LL operator*(const Point &a, const Point &b) { return a.x * b.x + a.y * b.y; } bool operator<(const Point &a, const Point &b) { return a.x == b.x? a.y < b.y: a.x < b.x; } LL operator^(const Point &a, const Point &b) { return a.x * b.y - a.y * b.x; } Point operator-(const Point &a, const Point &b) { return Point(a.x - b.x, a.y - b.y); } struct Cross_len { LL cross, len; }; bool operator==(const Cross_len &a, const Cross_len &b) { return a.cross == b.cross && a.len == b.len; } bool operator!=(const Cross_len &a, const Cross_len &b) { return !(a == b); } int n[2], top[2]; Point point[2][maxn], sta[2][maxn << 1]; int Next[maxn]; Cross_len cross_len[2][maxn << 1]; void ConvexHull(Point *p, int n, int &top, Point *sta) { top = 0; sort(p + 1, p + 1 + n); for(int i = 1; i <= n; ++i) { while(top > 1 && ((sta[top - 1] - sta[top - 2]) ^ (p[i] - sta[top - 2])) <= 0) { --top; } sta[top++] = p[i]; } int ttop = top; for(int i = n; i > 0; --i) { while(top > ttop && ((sta[top - 1] - sta[top - 2]) ^ (p[i] - sta[top - 2])) <= 0) { --top; } sta[top++] = p[i]; } --top; } void Change_to_Cross_len(Point *p, int n, Cross_len *c) { // for(int i = 0; i < n; ++i) { // printf("%lld %lld / ", p[i].x, p[i].y); // } // printf("\n"); Point p0 = p[0]; for(int i = 0; i < n - 1; ++i) { p[i] = p[i + 1] - p[i]; c[i].len = p[i] * p[i]; } p[n - 1] = p0 - p[n - 1]; c[n - 1].len = p[n - 1] * p[n - 1]; for(int i = 0; i < n; ++i) { c[i].cross = (p[i] * p[(i + 1) % n]) + (p[i] ^ p[(i + 1) % n]); } // for(int i = 0; i < n; ++i) { // printf("%lld %lld /%lld %lld: ", p[i].x, p[i].y, c[i].cross, c[i].len); // } // printf("\n"); } void get_next(Cross_len *str, int n) { int j = -1; Next[0] = -1; for(int i = 1; i < n; ++i) { while(j != -1 && str[j + 1] != str[i]) { j = Next[j]; } if(str[i] == str[j + 1]) { ++j; } Next[i] = j; } } bool kmp(Cross_len *str1, int n, Cross_len *str2, int m) { int j = -1; for(int i = 0; i < n; ++i) { while(j != -1 && str1[i] != str2[j + 1]) { j = Next[j]; } if(str1[i] == str2[j + 1]) { ++j; } if(j == m - 1) { return true; } } return false; } int main() { while(scanf("%d%d", &n[0], &n[1]) != EOF) { memset(point, 0, sizeof(point)); for(int i = 0; i < 2; ++i) { for(int j = 1; j <= n[i]; ++j) { scanf("%lld%lld", &point[i][j].x, &point[i][j].y); } ConvexHull(point[i], n[i], top[i], sta[i]); if(i == 0) { for(int j = 0; j < top[i]; ++j) { sta[i][j + top[i]] = sta[i][j]; } top[i] *= 2; } Change_to_Cross_len(sta[i], top[i], cross_len[i]); } get_next(cross_len[1], top[1]); if(kmp(cross_len[0], top[0], cross_len[1], top[1])) { printf("Yes\n"); } else { printf("No\n"); } } return 0; }
相关文章推荐
- 【Codeforces Round #502 (in memory of Leopoldo Taravilse, Div. 1 + Div. 2) D】The Wu
- Codeforces Round #428 (Div. 2) B. Game of the Rows(贪心)
- Codeforces Round #428 (Div. 2) B.Game of the Rows(贪心+炒鸡多坑的模拟)
- Codeforces Round #377 (Div. 2) B. Cormen — The Best Friend Of a Man
- Codeforces Round #377 (Div. 2) Cormen --- The Best Friend Of a Man
- Codeforces Round #251 (Div. 2) C. Devu and Partitioning of the Array
- 【Codeforces Round 326 (Div 2)E】【树链剖分】Duff in the Army 树上给定路径上编号最小的几个人
- Codeforces Round VK Cup 2015 - Round 1 (unofficial online mirror, Div. 1 only)E. The Art of Dealing with ATM 暴力出奇迹!
- Codeforces Round #428 (Div. 2) B. Game of the Rows (思维)
- Codeforces Beta Round #27 (Codeforces format, Div. 2) E. Number With The Given Amount Of Divisors 反素数
- Codeforces Round #189 (Div. 1) Kalila and Dimna in the Logging Industry 斜率DP
- Codeforces Round #342 (Div. 2) B. War of the Corporations 贪心
- Codeforces Round #215 (Div. 1) C. Sereja and the Arrangement of Numbers(欧拉图)
- Codeforces Round #258 (Div. 2) C. Predict Outcome of the Game
- Codeforces Round #249 (Div. 2)C Devu and Partitioning of the Array
- Codeforces Round #249 (Div. 2)C Devu and Partitioning of the Array
- Codeforces Round #124 (Div. 1) D. The Next Good String
- Educational Codeforces Round 7 F. The Sum of the k-th Powers 拉格朗日插值法
- Codeforces Round #439 (Div. 2) 869 C. The Intriguing Obsession
- Codeforces Round #403 div2 B. The Meeting Place Cannot Be Changed