Description

给两个多边形,问否在平移旋转不翻转不重叠的情况下拼成一个凸多边形。

Input

每组第一行一个数N表示第一个多边形的顶点数,下接N行按顺序(逆/顺时针)给出顶点坐标,再下一行给一个数M表示第二个多边形的顶点数,下接M行按顺序给出顶点坐标。

Output

对于每组数据,输出一行0/1,1表示能,0表示不能。

Sample Input

4
0 0
0 1
1 1
1 0
4
0 0
0 1
1 1
1 0
4
0 0
0 1
1 1
1 0
4
0 0
0 1
1 1
1 0

Sample Output

1
1

HINT

对于100%的数据,N<=1000,M<=1000,顶点坐标为实数,标程精度1e-8

题解:

平面计算几何题。每次枚举相拼的两条边,在按顺序扫过两个多边形对应的变,检查是否是无缝屏接,拼好后是否是凸多边形。

注意给点的顺序不一定都是逆时针的,先按照给点的顺序扫过每一条边,记录下角度的偏转情况。若最终偏转为-2π,则为顺时针;若为2π,则为逆时针。

通过倒着排序给出的点,使两个多边形都变成是逆时针的,就可以正常做了。

代码:

 var
i,j,k,l,n,m:longint;
a,b:array[-..,..]of extended;
tt:array[..]of extended;
e:extended;
function dis(x,y,xx,yy:extended):extended;
begin
exit(sqrt(sqr(x-xx)+sqr(y-yy)));
end;
function xj2(x,y:extended):extended;
var i,j,k,l:longint;
begin
if(abs(x)<0.0000001)and(y>)then exit(pi/);
if(abs(x)<0.0000001)and(y<)then exit(*pi/);
if(abs(y)<0.0000001)and(x>)then exit();
if(abs(y)<0.0000001)and(x<)then exit(pi);
if(x>)and(y>)then exit(arctan(y/x));
if(x>)and(y<)then exit(*pi-arctan(-y/x));
if(x<)and(y>)then exit(pi/+arctan(-x/y));
if(x<)and(y<)then exit(pi+arctan(y/x));
end;
function xj(x,y,xx,yy,xxx,yyy:extended):extended;
var z1,z2:extended;
begin
z1:=xj2(x-xx,y-yy);
z2:=xj2(xxx-xx,yyy-yy);
while z2>0.0000001+z1 do z2:=z2-*pi;
exit(z1-z2);
end;
function ss:longint;
var i,j,ii,jj,k,l:longint;
z1,z2,z3:extended;
begin
for i:= to n do
for j:= to m do
if abs(dis(a[i-,],a[i-,],a[i,],a[i,])
-dis(b[j+,],b[j+,],b[j,],b[j,]))<0.0000001 then
begin
z1:=xj(a[i-,],a[i-,],a[i-,],a[i-,],a[i,],a[i,]);
z2:=xj(b[j+,],b[j+,],b[j+,],b[j+,],b[j,],b[j,]);
while z2>0.0000001+z1 do z2:=z2-*pi;
if z1-z2>pi+0.0000001 then continue;
ii:=i+; jj:=j-; l:=;
while true do
begin
z1:=xj(a[ii-,],a[ii-,],a[ii-,],a[ii-,],a[ii,],a[ii,]);
z2:=xj(b[jj+,],b[jj+,],b[jj+,],b[jj+,],b[jj,],b[jj,]);
while z2>0.0000001+z1 do z2:=z2-*pi;
if z1-z2<0.0000001 then
begin
if abs(dis(a[ii-,],a[ii-,],a[ii,],a[ii,])
-dis(b[jj+,],b[jj+,],b[jj,],b[jj,]))<0.0000001 then
begin inc(ii); dec(jj); end else begin l:=; break; end;
continue;
end;
if z1-z2<pi-0.0000001 then
begin l:=; break; end;
break;
end;
if l= then
begin
for k:=ii to i+n- do
if xj(a[k-,],a[k-,],a[k,],a[k,],a[k+,],a[k+,])>pi+0.0000001
then begin l:=; break; end;
for k:=jj downto j-m+ do
if xj(b[k+,],b[k+,],b[k,],b[k,],b[k-,],b[k-,])<pi-0.0000001
then begin l:=; break; end;
if l= then exit();
end;
end;
exit();
end;
begin
while not eof do
begin
readln(n);
for i:= to n do readln(a[i,],a[i,]);
a[n+]:=a[]; a[]:=a[n]; e:=;
for i:= to n do
e:=e+xj(a[i-,],a[i-,],a[i,],a[i,],a[i+,],a[i+,])-pi;
if e> then
begin
for i:= to n div do begin tt:=a[i]; a[i]:=a[n-i+]; a[n-i+]:=tt; end;
end;
for i:= to n do a[i-n]:=a[i];
for i:= to n do a[i+n]:=a[i];
readln(m);
for i:= to m do readln(b[i,],b[i,]);
b[m+]:=b[]; b[]:=b[m]; e:=;
for i:= to m do
e:=e+xj(b[i-,],b[i-,],b[i,],b[i,],b[i+,],b[i+,])-pi;
if e> then
begin
for i:= to m div do begin tt:=b[i]; b[i]:=b[m-i+]; b[m-i+]:=tt; end;
end;
for i:= to m do b[i-m]:=b[i];
for i:= to m do b[i+m]:=b[i];
writeln(ss);
end;
end.

BZOJ2191Splite的更多相关文章

随机推荐

  1. [React] React Fundamentals: Using Refs to Access Components

    When you are using React components you need to be able to access specific references to individual ...

  2. Python重写C语言程序100例--Part1

    ''' [程序1] 题目:有1.2.3.4个数字,能组成多少个互不同样且无反复数字的三位数?都是多少? 1.程序分析:可填在百位.十位.个位的数字都是1.2.3.4.组成全部的排列后再去 掉不满足条件 ...

  3. VS C# 快捷键

    解决VS2010中工具箱的的不见的问题:按快捷键Ctrl+Alt+X 全屏:Shift+Alt+Enter注释选定内容:Ctrl+E+C/Crtr+E+U代码格式化:ctrl+E+F ======== ...

  4. 动态添加组件(XML)

    1.利用LayoutInflater的inflate动态加载XMLmLinearLayout = (LinearLayout)findViewById(R.id.LinearLayout_ID);La ...

  5. android多国语言文件夹

    android多国语言文件夹文件汇总如下:(有些语言的书写顺序可能跟中文是相反的) 中文(中国):values-zh-rCN 中文(台湾):values-zh-rTW 中文(香港):values-zh ...

  6. 当使用VS CODE 时,如果窗口中打开的文件无法识别HTML的话,可以使用以下方法添加要识别的文件类型

    找到该文件并修改\Microsoft VS Code\resources\app\extensions\html\package.json{ "name": "html& ...

  7. 学习笔记6_Java_day11_JSP_基础和入门(1、2)

    主要内容:1. JSP基础2. Cookie3. HttpSession ================================ JSP基础 1. jsp的作用: * Servlet: &g ...

  8. swift-01-利用元组判断字符串出现次数

    //问题的提出:有一个字符串 array = ["1","2","4","4","2"," ...

  9. iOS控件——UIView的viewWithTag:(int)findTag方法描述

    UIView拥有一个viewWithTag:(int)findTag方法,调用方式为[MyView viewWithTag:整形数字]该方法返回tag == findTag的控件.ios控件中允许多个 ...

  10. javascript 去除字符串中重复字符

    /** * 去除字符串中重复的字符,以下提供2种方法, * removeRepeat()为自己所想: * removeRepeat2()参考网上思路补充的 * removeRepeat3()敬请期待· ...