描述

While creating a customer logo, ACM uses graphical utilities to draw a picture that can later be cut into special fluorescent materials. To ensure proper processing, the shapes in the picture cannot intersect. However, some logos contain such intersecting shapes. It is necessary to detect them and decide how to change the picture.

Given a set of geometric shapes, you are to determine all of their intersections. Only outlines are considered, if a shape is completely inside another one, it is not counted as an intersection.

输入

Input contains several pictures. Each picture describes at most 26 shapes, each specified on a separate line. The line begins with an uppercase letter that uniquely identifies the shape inside the corresponding picture. Then there is a kind of the shape and two or more points, everything separated by at least one space. Possible shape kinds are:

• square: Followed by two distinct points giving the opposite corners of the square.

rectangle: Three points are given, there will always be a right angle
between the lines connecting the first point with the second and the
second with the third.
• line: Specifies a line segment, two distinct end points are given.
• triangle: Three points are given, they are guaranteed not to be co-linear.

polygon: Followed by an integer number N (3 ≤ N ≤ 20) and N points
specifying vertices of the polygon in either clockwise or anti-clockwise
order. The polygon will never intersect itself and its sides will have
non-zero length.

All points are always given as two integer coordinates X and Y
separated with a comma and enclosed in parentheses. You may assume that
|X|, |Y | ≤ 10000.

The picture description is terminated by a line containing a single
dash (“-”). After the last picture, there is a line with one dot (“.”).

输出

For
each picture, output one line for each of the shapes, sorted
alphabetically by its identifier (X). The line must be one of the
following:

• “X has no intersections”, if X does not intersect with any other shapes.
• “X intersects with A”, if X intersects with exactly 1 other shape.
• “X intersects with A and B”, if X intersects with exactly 2 other shapes.
• “X intersects with A, B, . . ., and Z”, if X intersects with more than 2 other shapes.

Please note that there is an additional comma for more than two
intersections. A, B, etc. are all intersecting shapes, sorted
alphabetically.

Print one empty line after each picture, including the last one.

样例输入

A square (1,2) (3,2)
F line (1,3) (4,4)
W triangle (3,5) (5,5) (4,3)
X triangle (7,2) (7,4) (5,3)
S polygon 6 (9,3) (10,3) (10,4) (8,4) (8,1) (10,2)
B rectangle (3,3) (7,5) (8,3)
-
B square (1,1) (2,2)
A square (3,3) (4,4)
-
.

样例输出

A has no intersections
B intersects with S, W, and X
F intersects with W
S intersects with B
W intersects with B and F
X intersects with B

A has no intersections
B has no intersections

题意

给你多边形,如果在内部则视为不相交,判断哪些是相交的

题解

把多边形按边存,如果两个多边形相交,那么一定存在两条边相交

判断两条边相交,先用俩矩形快速排斥,再用跨立实验,如果ab和cd相交,那么cd的两端一定在向量ab的两侧,可以通过abc和abd叉积相乘<0判断是否相交

然后就是存多边形,这里正方形和矩形另外的点得通过向量计算一下

PS:码农题,读输入,输出都恶心,题目不算太难

代码

 #include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
using namespace std;
struct point
{
double x,y;
point(double x=,double y=):x(x),y(y){}
};
bool judge(point a,point b,point c,point d)
{
if(!(min(a.x,b.x)<=max(c.x,d.x)&&min(c.y,d.y)<=max(a.y,b.y)&&min(c.x,d.x)<=max(a.x,b.x)&&min(a.y,b.y)<=max(c.y,d.y)))
return false;
double u,v,w,z;
u=(c.x-a.x)*(b.y-a.y)-(b.x-a.x)*(c.y-a.y);
v=(d.x-a.x)*(b.y-a.y)-(b.x-a.x)*(d.y-a.y);
w=(a.x-c.x)*(d.y-c.y)-(d.x-c.x)*(a.y-c.y);
z=(b.x-c.x)*(d.y-c.y)-(d.x-c.x)*(b.y-c.y);
return (u*v<=0.00000001&&w*z<=0.00000001);
}
vector<point>G[]; int main()
{
//freopen("A.txt","w",stdout);
int m;
double a,b;
char op[],shape[];
while(scanf("%s",op)!=EOF,op[]!='.')
{
for(int i=;i<;i++)G[i].clear();
while(op[]!='-')
{
int cnt=op[]-'A';
scanf("%s",shape);
if(shape[]=='s')///正方形
{
for(int i=;i<=;i++)
{
scanf(" (%lf,%lf)",&a,&b);
G[cnt].push_back(point(a,b));
}
double A=G[cnt][].x,B=G[cnt][].y,C=G[cnt][].x,D=G[cnt][].y;
G[cnt].push_back(point((A*1.0+B+C-D)/2.0,(-A*1.0+B+C+D)/2.0));
G[cnt].push_back(point((A*1.0-B+C+D)/2.0,(A*1.0+B-C+D)/2.0));
swap(G[cnt][],G[cnt][]);
G[cnt].push_back(G[cnt][]);
}
if(shape[]=='r')///矩形
{
for(int i=;i<=;i++)
{
scanf(" (%lf,%lf)",&a,&b);
G[cnt].push_back(point(a,b));
}
G[cnt].push_back(point(G[cnt][].x*1.0+G[cnt][].x-G[cnt][].x,G[cnt][].y*1.0+G[cnt][].y-G[cnt][].y));
G[cnt].push_back(G[cnt][]);
}
if(shape[]=='l')///线
{
for(int i=;i<=;i++)
{
scanf(" (%lf,%lf)",&a,&b);
G[cnt].push_back(point(a,b));
}
}
if(shape[]=='t')///三角形
{
for(int i=;i<=;i++)
{
scanf(" (%lf,%lf)",&a,&b);
G[cnt].push_back(point(a,b));
}
G[cnt].push_back(G[cnt][]);
}
if(shape[]=='p')///多边形
{
scanf("%d",&m);
for(int i=;i<=m;i++)
{
scanf(" (%lf,%lf)",&a,&b);
G[cnt].push_back(point(a,b));
}
G[cnt].push_back(G[cnt][]);
}
scanf("%s",op);
}
for(int i=;i<;i++)
{
int flag=;
set<int>SET;
if((int)G[i].size()==)continue;
for(int j=;j<(int)G[i].size()-;j++)
{
for(int k=;k<;k++)
{
if((int)G[k].size()==||i==k)continue;
for(int l=;l<(int)G[k].size()-;l++)
{
if(judge(G[i][j],G[i][j+],G[k][l],G[k][l+]))
{
flag=;
SET.insert(k);
break;
}
}
}
}
if(flag==)
{
vector<int>VEC(SET.begin(),SET.end());
int len=(int)VEC.size();
printf("%c intersects with",i+'A');
if(len==)
{printf(" %c and %c\n",VEC[]+'A',VEC[]+'A');continue;}
for(int l=;l<len-;l++)
printf(" %c,",VEC[l]+'A');
if(len>)
printf(" and %c",VEC[len-]+'A');
else
printf(" %c",VEC[len-]+'A');
printf("\n");
}
else
printf("%c has no intersections\n",i+'A');
}
printf("\n");
}
return ;
}

TZOJ 2560 Geometric Shapes(判断多边形是否相交)的更多相关文章

  1. POJ 3449 Geometric Shapes 判断多边形相交

    题意不难理解,给出多个多边形,输出多边形间的相交情况(嵌套不算相交),思路也很容易想到.枚举每一个图形再枚举每一条边 恶心在输入输出,不过还好有sscanf(),不懂可以查看cplusplus网站 根 ...

  2. POJ 3449 Geometric Shapes(判断几个不同图形的相交,线段相交判断)

    Geometric Shapes Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 1243   Accepted: 524 D ...

  3. Geometric Shapes (poj3449多边形相交)

    题意:给你一些多边形的点,判断每个多边形和那些多边形相交,编号按照字典序输出 思路:枚举每个多边形的每条边看是否相交,这里的相交是包括端点的,关键是给你正方形不相邻两个点求另外两个点怎么求,长方形给你 ...

  4. POJ 3449 Geometric Shapes --计算几何,线段相交

    题意: 给一些多边形或线段,输出与每一个多边形或线段的有哪一些多边形或线段. 解法: 想法不难,直接暴力将所有的图形处理成线段,然后暴力枚举,相交就加入其vector就行了.主要是代码有点麻烦,一步一 ...

  5. poj3449 Geometric Shapes【计算几何】

    含[判断线段相交].[判断两点在线段两侧].[判断三点共线].[判断点在线段上]模板   Geometric Shapes Time Limit: 2000MS   Memory Limit: 655 ...

  6. POJ 3449 Geometric Shapes (求正方形的另外两点)

    Geometric Shapes Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 1470   Accepted: 622 D ...

  7. POJ 3449 Geometric Shapes

    判断两个多边形是否相交,只需判断边是否有相交. 编码量有点大,不过思路挺简单的. #include<cstdio> #include<cstring> #include< ...

  8. POJ1584 判断多边形是否为凸多边形,并判断点到直线的距离

    求点到直线的距离: double dis(point p1,point p2){   if(fabs(p1.x-p2.x)<exp)//相等的  {    return fabs(p2.x-pe ...

  9. 计算几何--判断两条线段相交--poj 2653

    Pick-up sticks Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 8862   Accepted: 3262 De ...

随机推荐

  1. DOM节点的增删改查以及class属性的操作

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

  2. Arraylist JDk1.8扩容和遍历

    Arraylist作为最简单的集合,需要熟悉一点,记录一下---->这边主要是注意一下扩容和遍历的过程 请看以下代码 public static void main(String[] args) ...

  3. 在page cache中的页,如果当时没有进程read或者write,引用计数到底该为多少

    在一次偶然的机会,在研究如何降低pagecache占用的过程中,走查了 invalidate_mapping_pages的代码: 通过调用 __pagevec_lookup 在radix树中收集一部分 ...

  4. Java如何创建参数个数不限的函数

    可变的参数类型,也称为不定参数类型.英文缩写是varargus,还原一下就是variable argument type.通过它的名字可以很直接地看出来,这个方法在接收参数的时候,个数是不定的. pu ...

  5. android Button、TabLayout英文自动改小写为大写的问题

    如果是Button自动大写问题,直接设置Button的 textAllCaps="false" 即可: 如果是TabLayout出现全大写问题,先在style.xml加入属性: & ...

  6. ArcGIS案例学习笔记-栅格数据分区统计(平均高程,污染浓度,污染总量,降水量)

    ArcGIS案例学习笔记-栅格数据分区统计(平均高程,污染浓度,污染总量,降水量) 联系方式:谢老师,135-4855-4328,xiexiaokui@qq.com 目的:针对栅格数据,利用多边形面要 ...

  7. IE (第二部分) 浏览器 中 关于浏览器模式和文本模式

    判断真正的 IE 版本 很多 JS 框架都通过 UA 判断 IE 的版本.对于 IE6,这种做法没问题( IE6 没有浏览器模式的概念,也没有其它 IE 可以把浏览器模式改为 IE6:IE7 虽然也没 ...

  8. 在Unity中使用Lua脚本

    前言:为什么要用Lua首先要说,所有编程语言里面,我最喜欢的还是C#,VisualStudio+C#,只能说太舒服了.所以说,为什么非要在unity里面用Lua呢?可能主要是闲的蛋疼.....另外还有 ...

  9. Ubuntu下好的PDF阅读器介绍

    我们经常要学习,看论文,如果有好的PDF阅读器,可以做笔记,对以后查看和记忆是有帮助的 这里推荐用:okular 这里是基本操作哦 1: 安装 sudo apt-get install okular ...

  10. flask_script 创建自定义命令行

    创建管理员账号:         在服务器部署后,由于管理员账号没有申请的路径,需要在一开始的时候设定管理员账号,如果使用过程中需要新增管理员账号,十分不方便,在flask_script中可以通过命令 ...