描述

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. web安全/渗透测试--1--web安全原则

    web 安全:  https://blog.csdn.net/wutianxu123/article/category/8037453/2 web安全原则 安全应该是系统开发之初就考虑的问题.换句话说 ...

  2. c# sql等微型代码工具LinqPad

  3. python 连接 Oracle 乱码问题(cx_Oracle)

    用python连接Oracle是总是乱码,最后发现时oracle客户端的字符编码设置不对. 编写的python脚本中需要加入如下几句: import os os.environ['NLS_LANG'] ...

  4. Sql Server 中由数字转换为指定长度的字符串

    一个列的数据类型是 int ,从 1 开始自动增长,另一个列是字符串,现在想把 int 列转换成 九个字符,比如 1 转换后就是 000000001 ,添到字符串列,怎么实现呢? set @imaxU ...

  5. 4.ClassLink - 一种新型的VPC 经典网络的连接方式

    阿里云CLassLink文档地址:https://help.aliyun.com/document_detail/65412.html?spm=a2c4g.11186623.2.9.41a25a07F ...

  6. Servlet之ServletContext获取web上下文路径、全局参数、和Attribute(域)

    1)获取web上下文路径 public void doGet(HttpServletRequest request, HttpServletResponse response) throws Serv ...

  7. Linux性能测试分析命令_vmstat

    vmstat命令主要是对操作系统的虚拟内存.进程.IO读写.CPU活动等整体情况进行统计.但是它不能对某个进程进行深入分析. vmstat基本语法 命令使用格式:vmstat [options] [d ...

  8. 面图层拓扑检查和错误自动修改—ArcGIS案例学习笔记

    面图层拓扑检查和错误自动修改-ArcGIS案例学习笔记 联系方式:谢老师,135_4855_4328,xiexiaokui#139.com 数据源: gis_ex10\ex01\parcel.shp, ...

  9. (转)如何禁用Windows 10系统的触摸屏

    https://baijiahao.baidu.com/s?id=1593890738706748667 现在许多优质的Windows 10个人电脑都配备了触摸屏,因为触摸屏的日益普及,Windows ...

  10. java的特点

    java是一种跨平台.适合于分布式计算机环境的面向对象编程语言.具有以下特性:简单性.面向对象.分布性.解释性.可靠.安全.平台无关.可移植性.高性能.多线程.动态性等特点. 面向过程和面向对象可以用 ...