Codeforces Round #502 (in memory of Leopoldo Taravilse, Div. 1 + Div. 2) E. The Supersonic Rocket
这道题比赛之后被重新加了几个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的更多相关文章
- 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 ...
- 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 ...
- Codeforces Round #502 (in memory of Leopoldo Taravilse, Div. 1 + Div. 2)
第一次参加cf的比赛 有点小幸运也有点小遗憾 给自己定个小目标 1500[对啊我就是很菜qvq A. The Rank 难度:普及- n位学生 每个学生有四个分数 然鹅我们只需要知道他的分数和 按分数 ...
- 【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 ...
- Codeforces Round #502
Codeforces Round #502 C. The Phone Number 题目描述:求一个\(n\)排列,满足\(LIS+LDS\)最小 solution 枚举\(LIS\),可证明\(LD ...
- 【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 ...
- Codeforces Round #195 A B C 三题合集 (Div. 2)
A 题 Vasily the Bear and Triangle 题目大意 一个等腰直角三角形 ABC,角 ACB 是直角,AC=BC,点 C 在原点,让确定 A 和 B 的坐标,使得三角形包含一个矩 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- 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 ...
随机推荐
- Springboot中使用ibatis输出日志
logging.level.org.apache.ibatis=DEBUG logging.level.org.mybatis=DEBUG logging.level.java.sql.Connect ...
- Python 学习笔记(十四)Python类(三)
完善类的内容 示例: #! /usr/bin/env python # coding =utf-8 #通常类名首字母大写 class Person(object): """ ...
- oracle 11G dataguard 恢复
检查主备机的sys 密码是否一致,忘记密码可以修改,同步 .alter user sys identified by xxx: orapwd file=oraxxx.ora password=admi ...
- iOS:cocoapods 配置相关(19-04-02更)
1.gem sources 2.libwebp 1.gem sources 因为,mac更新,cocoapods也要更新,使用下面指令,提示找不到.org,原因是淘宝的镜像源.org换成.com,所以 ...
- objc单例的两种安全实现方案
所有转出博客园,请您注明出处:http://www.cnblogs.com/xiaobajiu/p/4122034.html objc的单例的两种安全实现方案 首先应该知道单例的实现有两大类,一个是懒 ...
- vue面试题!!!
由于公司需要,需要把项目拆分,前端使用vue框架.最近面试vue总结的试题 1:mvvm框架是什么?它和其他框架的区别是什么? mvvm 全称model view viewModel,model数据模 ...
- 20181031noip模拟赛T1
思路: 我们会发现不合法的位置只有两种情况 要么在前半边,要么在后半边 那么,我们将序列劈两次 使两次的长度分别为: (n为偶数时要特判一下,因为根本不可能) (n/2),(n/2+1) (n/2+1 ...
- MySQL数据约束
定义:建表时在各字段类型后设置,用来对用户操作表的数据进行约束. 代码: 1.默认值 : default ' ' 作用:当用户对使用默认值的字段不插入值的时候,就使用默认值(自动填充). 注意: ...
- Nginx与Tomcat实现请求动态数据与请求静态资源的分离
上篇博客说明了Nginx在应用架构中的作用,以及负载均衡的思路.这篇实践一下其中的访问静态资源与访问动态资源的操作. 一.认识访问静态资源与访问动态资源的区别 静态资源:指存储在硬盘内的数据,固定的数 ...
- redis必会
1.NosqL 非关系型数据库,里面包含Redis和MondoDB2.为什么会用到关系型数据库?因为当数据量太多,访问人数过多的时候,在访问关系型数据库时会到硬盘里进行读写过多 这样就会导致访问速度很 ...