描述

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. 深度学习原理与框架-卷积神经网络基本原理 1.卷积层的前向传播 2.卷积参数共享 3. 卷积后的维度计算 4. max池化操作 5.卷积流程图 6.卷积层的反向传播 7.池化层的反向传播

    卷积神经网络的应用:卷积神经网络使用卷积提取图像的特征来进行图像的分类和识别       分类                        相似图像搜索                        ...

  2. 机器学习进阶-目标跟踪-KCF目标跟踪方法 1.cv2.multiTracker_create(构造选框集合) 2. cv2.TrackerKCF_create(获得KCF追踪器) 3. cv2.resize(变化图像大小) 4.cv2.selectROI(在图像上框出选框)

    1. tracker = cv2.multiTracker_create() 获得追踪的初始化结果 2.cv2.TrackerKCF_create() 获得KCF追踪器 3.cv2.resize(fr ...

  3. 06-padding(内边距)

    padding padding:就是内边距的意思,它是边框到内容之间的距离 另外padding的区域是有背景颜色的.并且背景颜色和内容的颜色一样.也就是说background-color这个属性将填充 ...

  4. java自定义抛出的异常Exception

    package com.zhanzhuang.exception; public class CustomizeException { public static void main(String[] ...

  5. html 基础之a标签的属性target解析

    学习前端,有很多标签其实有很多不同的功能,但是用到的不多,所以就没有发现:当发现的时候,觉得很不可思议,有耳目一新的感觉.例如a 标签,之前只是知道,使用a标签,可以打开一个链接,然后访问一个新的页面 ...

  6. 遍历DOM树,过滤节点

    jQuery还提供以下方法来过滤节点.  方法  说明  first()  获取第一个,示例 $('li').last()  last()  获取最后一个,示例$('li').last()  eq() ...

  7. python实现根据指定字符截取对应的行的内容

    工作中遇到的,在一个.c文件中有很多函数,这个.c是自动生成的,需要将所有的函数通过extern放到.h中,每个函数都是UINT32 O_开头,通过正则表达式进行字符匹配以及通过linecache来截 ...

  8. Celery + RabbitMq 示意图

    一直搞不清楚消息队列和任务队列是如何结合的,直到碰到了 :http://www.cnblogs.com/jijizhazha/p/8086119.html 中的图,恍然大悟,凭借自己的理解,画了这幅组 ...

  9. git-02 下载代码

  10. Spring3.0学习1.1(模拟spring)

    层次划分 面向抽象编程  带来极大的灵活性 IOC(DI)  依赖注入 控制反转: 正式使用spring IOC   控制反转 不用自己写实现 由容器完成 建议使用appicatiioncontext ...