Codeforces 1017E The Supersonic Rocket 凸包,计算几何,字符串,KMP
原文链接https://www.cnblogs.com/zhouzhendong/p/CF1017E.html
题目传送门 - CF1017E
题意
给定两个点集,并构成两个凸包。
问这两个凸包是否可以通过旋转和平移重合。
每一个凸包的点数 $\leq 10^5$ 。
题解
建两个凸包,注意一下,建出来的凸包要避免凸包外围连续三点共线。
然后把每一个凸包的边长、拐角信息记录下来,形成一个序列,判断两个凸包对应的序列是否循环同构即可。注意一下拐角信息不能只存叉积。
例如赛后加上的第 55 组数据: 4 0 0 1 0 1 1 2 1 0 1 1 1 2 0 1 0
判断字符串循环同构:倍长一个串,另一个在上面 kmp 。
注意一下并不是匹配了就可以了,要保证匹配的位置为一个信息块的结尾。
代码
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=600005;
LL read(){
LL x=0;
char ch=getchar();
while (!isdigit(ch))
ch=getchar();
while (isdigit(ch))
x=(x<<1)+(x<<3)+ch-48,ch=getchar();
return x;
}
int n,m;
struct Point{
int x,y;
}p1[N],p2[N],O;
LL sqr(int x){
return 1LL*x*x;
}
LL dis(Point a,Point b){
return sqr(a.x-b.x)+sqr(a.y-b.y);
}
LL cross(Point a,Point b,Point c){
return 1LL*(b.x-a.x)*(c.y-a.y)-1LL*(c.x-a.x)*(b.y-a.y);
}
bool cmp_O(Point a,Point b){
if (a.y==b.y)
return a.x<b.x;
return a.y<b.y;
}
bool cmp_Angle(Point a,Point b){
LL c=cross(O,a,b);
if (c==0)
return dis(O,a)<dis(O,b);
return c>0;
}
int st[N],top;
int Make_Convex(Point P[],int n){
for (int i=2;i<=n;i++)
if (!cmp_O(P[1],P[i]))
swap(P[1],P[i]);
O=P[1];
sort(P+2,P+n+1,cmp_Angle);
top=0;
st[++top]=1,st[++top]=2;
for (int i=3;i<=n;i++){
while (top>=2&&cross(P[st[top-1]],P[st[top]],P[i])<=0)
top--;
st[++top]=i;
}
for (int i=1;i<=top;i++)
P[i]=P[st[i]];
return top;
}
LL s1[N],s2[N];
int Fail[N];
void KMP(LL s[],int n){
Fail[0]=Fail[1]=0;
for (int i=2;i<=n;i++){
int k=Fail[i-1];
while (k>0&&s[i]!=s[k+1])
k=Fail[k];
Fail[i]=k+(s[k+1]==s[i]?1:0);
}
}
bool check(){
int k=0;
for (int i=1;i<=n*6;i++){
while (k>0&&s2[k+1]!=s1[i])
k=Fail[k];
if (s2[k+1]==s1[i])
k++;
if (k>=m*3){
if (i%3==0)
return 1;
else
k=Fail[k];
}
}
return 0;
}
int main(){
n=read(),m=read();
for (int i=1;i<=n;i++)
p1[i].x=read(),p1[i].y=read();
for (int i=1;i<=m;i++)
p2[i].x=read(),p2[i].y=read();
n=Make_Convex(p1,n);
m=Make_Convex(p2,m);
for (int i=1;i<=n;i++){
s1[i*3-2]=dis(p1[i],p1[i%n+1]);
s1[i*3-1]=cross(p1[i],p1[i%n+1],p1[(i+1)%n+1]);
s1[i*3]=dis(p1[i],p1[(i+1)%n+1]);
}
for (int i=1;i<=m;i++){
s2[i*3-2]=dis(p2[i],p2[i%m+1]);
s2[i*3-1]=cross(p2[i],p2[i%m+1],p2[(i+1)%m+1]);
s2[i*3]=dis(p2[i],p2[(i+1)%m+1]);
}
for (int i=1;i<=n*3;i++)
s1[i+n*3]=s1[i];
KMP(s2,m*3);
puts(n==m&&check()?"YES":"NO");
return 0;
}
Codeforces 1017E The Supersonic Rocket 凸包,计算几何,字符串,KMP的更多相关文章
- CodeForces - 1017E :The Supersonic Rocket (几何+KMP,判定凸包是否同构)
After the war, the supersonic rocket became the most common public transportation. Each supersonic r ...
- hdu 5510 Bazinga(字符串kmp)
Bazinga Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Sub ...
- hdu1686字符串kmp
The French author Georges Perec (1936–1982) once wrote a book, La disparition, without the letter 'e ...
- 模板—字符串—KMP(单模式串,单文本串)
模板—字符串—KMP(单模式串,单文本串) Code: #include <cstdio> #include <cstring> #include <algorithm& ...
- 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) E. The Supersonic Rocket
这道题比赛之后被重新加了几个case,很多人现在都过不了了 算法就是先求凸包,然后判断两个凸包相等 我们可以吧凸包序列化为两点距离和角度 角度如果直接拿向量的叉积是不对的,,因为钝角和锐角的叉积有可能 ...
- bzoj 1964: hull 三维凸包 计算几何
1964: hull 三维凸包 Time Limit: 1 Sec Memory Limit: 64 MBSubmit: 54 Solved: 39[Submit][Status][Discuss ...
- [codeforces/gym/101350/L]维护“凸包”
题目链接:http://codeforces.com/gym/101350/problems 给定n个墙,每个墙有一个高度,要支持动态修改墙的高度和查询这个“容器”能盛多少水. (队友)观察发现,能盛 ...
- HDU 1392 Surround the Trees(凸包*计算几何)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1392 这里介绍一种求凸包的算法:Graham.(相对于其它人的解释可能会有一些出入,但大体都属于这个算 ...
随机推荐
- thymeleaf:日常使用总结
1.th:href 获得当前的根路径 th:href="@{/}" 2.select输出并自动选中 <select class="form-control sele ...
- 搭建基于IDEA+Selenium+Java+TestNG+Maven+Jenkins+SVN的Web端UI自动化测试环境
第一步:工具下载安装配置 JDK安装与配置 IDEA安装与配置 Maven安装与配置 Tomcat部署与配置 Jenkins部署与配置 Svn安装与配置 各浏览器驱动下载与配置 第二步:集成各个工具到 ...
- reportNG定制化之失败截图及日志
先从github上拉下 reportNg的源代码 reportng 拉下源码后我们使用IDEA进行导入 1.reportng.properties 增加部分类表项 这里我们直接在末尾添加 log=L ...
- dubbo @Activate 注解使用和实现解析
Activate注解表示一个扩展是否被激活(使用),可以放在类定义和方法上, dubbo用它在spi扩展类定义上,表示这个扩展实现激活条件和时机. 先看下定义: @Documented @Retent ...
- Docker架构图
Docker架构图 服务器---主机系统中通过Cgroup和Namespace-----------划分成多个bins/libs---------------每个app运行在独立的bins/libs中 ...
- 查看mysql库中所有表的信息--INFORMATION_SCHEMA
第一个查询看看库里有多少个表,表名等select * from INFORMATION_SCHEMA.TABLES information_schema这张数据表保存了MySQL服务器所有数据库的信息 ...
- jdbctemplate 调用oracle 有返回(会话型临时表数据的)结果的存储过程
注:本文为博主 原创. jdbctemplate 调用oracle存储过程 事务 临时表 有返回结果 1:java 代码 本逻辑代码本是想把 java 代码里的list<Strign>类 ...
- Oracle12c Release1 安装图解(详解)
Oracle12c Release1 安装图解(详解) Oracle12c 终于发布了,代号为 c,即为 Cloud(云),替代了网格 (Grid)运算. 我的机器基础环境:Windows8(x64) ...
- nginx(一)之默认配置文件
首先是nginx.conf vim /etc/nginx/nginx.conf user nginx; // 设置nginx服务的系统使用用户 worker_processes 1; // 工作进程数 ...
- SpringBoot多环境区分
1.修改application.yml配置文件 spring: profiles: active: cppdy datasource: driver-class-name: com.mysql.jdb ...