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 ...
随机推荐
- Reading SBAR SDN flow-Based monitoring and Application Recognition
概要 在sdn下,控制平面基于网络测量的的数据控制网络,而细粒度的管理得益于细粒度的测量数据.针对sdn环境下的细粒度测量(识别具体应用程序),可以实现对细粒度的流量管控. 设计了识别系统SBAR,对 ...
- 分享cropper剪切单张图片demo
<!DOCTYPE html> <html lang="zh-cn"> <head> <meta charset="UTF-8& ...
- pl/sql下载
详解Oracle客户端工具:PL/SQL工具下载: 下载地址:http://www.oraclejsq.com/article/010100114.html
- JS-instanceof 与typeof
通常来讲,使用 instanceof 就是判断一个实例是否属于某种类型 而typeof 无论引用的是什么类型的对象,它都返回 "object" var arr=[1,2,3]; ...
- java 关于String
1.两种创建方式 String str1 = "abc"; //字面量创建 String str2 = new String("abc"); //构造方法创建 ...
- 执行mongod其他实例出现的问题
windows环境下,配置其他mongo实例,会出现一些问题 1.配置路径不对,执行bat文件时出现闪屏 根据提示创建C:\data\db\ 目录(因为mongodb默认在/data/db下创建数据库 ...
- python学习笔记(二)python基础知识(交作业)
交作业 #!/usr/bin/env python # coding: utf-8 # # 1. 每个用户购买了多少不同种类的产品 # filename = 'train.txt' import sy ...
- 大数据Hadoop的HA高可用架构集群部署
1 概述 在Hadoop 2.0.0之前,一个Hadoop集群只有一个NameNode,那么NameNode就会存在单点故障的问题,幸运的是Hadoop 2.0.0之后解决了这个问题,即支持N ...
- 开了几天的phpmyadmin的总结
近来无事,免费体验了一波腾讯云的vps,打了一个phpstudy,全部默认的配置,只不过,没有给他写入文件的权限 开启了日志,看了下,这几天黑客们的活动 首先,有两三个ip来爆破我的phpmyadmi ...
- java->php之在线子域名查询-接口光速版
因为不懂java,所以 用php重写了大佬的 在线子域名查询-接口光速版 http://sbd.ximcx.cn/ 这是大佬的 然后 改一下 ,用php 其实就是改了几行代码而已,jquery和aj ...