这道题比赛之后被重新加了几个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) E. The Supersonic Rocket的更多相关文章

  1. E. The Supersonic Rocket Codeforces Round #502 (in memory of Leopoldo Taravilse, Div. 1 + Div. 2)

    http://codeforces.com/contest/1017/problem/E 凸包模板+kmp #include <cstdio> #include <cstdlib&g ...

  2. Codeforces Round #502 (in memory of Leopoldo Taravilse, Div. 1 + Div. 2) G. The Tree

    G. The Tree time limit per test 3 seconds memory limit per test 256 megabytes input standard input o ...

  3. Codeforces Round #502 (in memory of Leopoldo Taravilse, Div. 1 + Div. 2)

    第一次参加cf的比赛 有点小幸运也有点小遗憾 给自己定个小目标 1500[对啊我就是很菜qvq A. The Rank 难度:普及- n位学生 每个学生有四个分数 然鹅我们只需要知道他的分数和 按分数 ...

  4. 【Codeforces Round #502 (in memory of Leopoldo Taravilse, Div. 1 + Div. 2) D】The Wu

    [链接] 我是链接,点我呀:) [题意] 给你n个字符串放在multiset中. 这些字符串都是长度为m的01串. 然后给你q个询问 s,k 问你set中存在多少个字符串t 使得∑(t[i]==s[i ...

  5. Codeforces Round #502

    Codeforces Round #502 C. The Phone Number 题目描述:求一个\(n\)排列,满足\(LIS+LDS\)最小 solution 枚举\(LIS\),可证明\(LD ...

  6. 【Codeforces Round #502 (Div. 1 + Div. 2) 】

    A:https://www.cnblogs.com/myx12345/p/9843032.html B:https://www.cnblogs.com/myx12345/p/9843050.html ...

  7. Codeforces Round #195 A B C 三题合集 (Div. 2)

    A 题 Vasily the Bear and Triangle 题目大意 一个等腰直角三角形 ABC,角 ACB 是直角,AC=BC,点 C 在原点,让确定 A 和 B 的坐标,使得三角形包含一个矩 ...

  8. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  9. Codeforces Round #262 (Div. 2) 1003

    Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...

随机推荐

  1. vim全选复制粘贴

    感谢来源:http://blog.sina.com.cn/s/blog_6e70abbd0100zbk9.html ggVG #gg: 光标跳转到首行,在vim才有效,vi中无效 #V 是进入Visu ...

  2. 数据包式套接字:基于UDP协议的Socket网络编程

    步骤: 1.利用DatagramPacket封装数据包: 2.利用DatagramSocket发送数据包: 3.利用DatagramSocket接收数据包: 4.利用DatagramPacket处理数 ...

  3. STM32启动代码分析

    STM32启动文件简单分析(STM32F10x.s适用范围)定时器, 型号, 名字在<<STM32不完全手册里面>>,我们所有的例程都采用了一个叫STM32F10x.s的启动文 ...

  4. staticmethod classmethod

    1. 静态方法 @staticmethod 只是名义上归类管,实际上静态方法里访问不了类或者实例中的任何属性 2. 类方法 @classmethod 只能访问类变量,不能访问实例变量 3.属性方法 @ ...

  5. office365离线安装

    office版本是在线安装,每次安装比较麻烦,所以还是离线安装合适,这里推荐一篇博文https://www.cnblogs.com/Devopser/p/7919245.html 但是由于部署工具变化 ...

  6. jquery实现复选框的全选、全不选、反选

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  7. js数组定义和方法 (包含ES5新增数组方法)

    数组Array 1. 数组定义 一系列数据的集合成为数组.数组的元素可以为任何类型的数据(包括数组,函数等),每个元素之间用逗号隔开,数组格式:[1,2,3]. 2. 数组创建方式 (1) 字面量方法 ...

  8. js数组的处理使用

    var users = [ {name: "张含韵", "email": "zhang@email.com"}, {name: " ...

  9. Delphi Android下包含第三方DEX

    1.将jar转换为dex call dx --dex -verbose --output=.\output\dex\test_classes.dex --positions=lines .\outpu ...

  10. Docker Toolbox下配置国内镜像源-阿里云加速器

    Docker machine安装 Docker Machine是一个简化Docker安装的命令行工具,通过一个简单的命令行即可在相应的平台上安装Docker,比如VirtualBox. Digital ...