Geometric Shapes - POJ 3449(多边形相交)
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<algorithm>
using namespace std; const int MAXN = ;
const double EPS = 1e-; int Sign(double t)
{
if(t > EPS)return ;
if(fabs(t) < EPS)return ;
return -;
}
struct Point
{
double x, y;
Point(double x=, double y=):x(x),y(y){}
Point operator - (const Point &tmp)const{
return Point(x-tmp.x, y-tmp.y);
}
double operator ^(const Point &tmp)const{
return x*tmp.y - y*tmp.x;
}
};
struct Segment
{
Point S, E;
Segment(Point S=, Point E=):S(S), E(E){}
bool Intersect(const Segment &tmp)const{
int t1 = Sign((S-E)^(tmp.S-E));
int t2 = Sign((S-E)^(tmp.E-E)); return abs(t1+t2) != ;
}
};
struct Shapes
{
Segment sg[MAXN];
int N;
};
bool Find(int u, int v, Shapes a[])
{
for(int i=; i<a[u].N; i++)
for(int j=; j<a[v].N; j++)
{
if(a[u].sg[i].Intersect(a[v].sg[j]) && a[v].sg[j].Intersect(a[u].sg[i]))
return true;
} return false;
}
void Link(Shapes a[], int k, Point p[])
{
int i, N=a[k].N;
p[N] = p[];
for(i=; i<=N; i++)
a[k].sg[i-] = Segment(p[i-], p[i]);
}
int main()
{
char Id[MAXN], s[MAXN], s1[MAXN], s2[MAXN];
Shapes a[MAXN];
Point p[MAXN]; memset(a, , sizeof(a)); while(scanf("%s", Id) != EOF && Id[] != '.')
{
if(Id[] == '-')
{
for(int i=; i<MAXN; i++)
{
if(a[i].N)
{///如果这个符号的形状存在
int ans[MAXN], k=;
for(int j=; j<MAXN; j++)
{
if(!a[j].N || i==j)
continue;
if(Find(i, j, a) == true)
ans[k++] = j;
} if(k == )
printf("%c intersects with %c\n", i+'A', ans[]+'A');
else if(k == )
printf("%c has no intersections\n", i+'A');
else
{
printf("%c intersects with %c", i+'A', ans[]+'A');
for(int t=; t<k-; t++)
printf(", %c", ans[t]+'A');
if(k == )
printf(" and %c\n", ans[k-]+'A');
else
printf(", and %c\n", ans[k-]+'A');
}
}
}
printf("\n");
memset(a, , sizeof(a));
}
else
{
scanf("%s", s);
int k = Id[] - 'A'; if(strcmp(s, "square") == )
{///正方形
a[k].N = ;
scanf("%s%s", s1, s2);
sscanf(s1, "(%lf,%lf)", &p[].x, &p[].y);
sscanf(s2, "(%lf,%lf)", &p[].x, &p[].y); p[].x = (p[].x+p[].x + p[].y-p[].y)/;
p[].y = (p[].x-p[].x + p[].y+p[].y)/;
p[].x = (p[].x+p[].x + p[].y-p[].y)/;
p[].y = (p[].x-p[].x + p[].y+p[].y)/;
}
else if(strcmp(s, "line") == )
{///直线
a[k].N = ;
scanf("%s%s", s1, s2);
sscanf(s1, "(%lf,%lf)", &p[].x, &p[].y);
sscanf(s2, "(%lf,%lf)", &p[].x, &p[].y);
}
else if(strcmp(s, "rectangle") == )
{///长方形
a[k].N = ;
for(int t=; t<; t++)
{
scanf("%s", s1);
sscanf(s1, "(%lf,%lf)", &p[t].x, &p[t].y);
}
p[].x = p[].x-p[].x+p[].x;
p[].y = p[].y-p[].y+p[].y;
}
else if(strcmp(s, "triangle") == )
{///三角形
a[k].N = ;
for(int t=; t<; t++)
{
scanf("%s", s1);
sscanf(s1, "(%lf,%lf)", &p[t].x, &p[t].y);
}
}
else if(strcmp(s, "polygon") == )
{///多边形
scanf("%d", &a[k].N); for(int t=; t<a[k].N; t++)
{
scanf("%s", s1);
sscanf(s1, "(%lf,%lf)", &p[t].x, &p[t].y);
}
} Link(a, k, p);
}
} return ;
}
Geometric Shapes - POJ 3449(多边形相交)的更多相关文章
- POJ 3449 Geometric Shapes --计算几何,线段相交
题意: 给一些多边形或线段,输出与每一个多边形或线段的有哪一些多边形或线段. 解法: 想法不难,直接暴力将所有的图形处理成线段,然后暴力枚举,相交就加入其vector就行了.主要是代码有点麻烦,一步一 ...
- poj 3082多边形相交 'Roid Rage
题意是判断多边形是否相交 主要的思路就是判断每一个点是否在另外的多变形内 判断一个点是否在另一个多边形内主要思路是: 判断的那个点向左边做射线,如果射线与多边形的交点为奇数个则在多边形内,偶数个则不在 ...
- POJ 3449 Geometric Shapes(判断几个不同图形的相交,线段相交判断)
Geometric Shapes Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 1243 Accepted: 524 D ...
- TZOJ 2560 Geometric Shapes(判断多边形是否相交)
描述 While creating a customer logo, ACM uses graphical utilities to draw a picture that can later be ...
- POJ 3449 Geometric Shapes (求正方形的另外两点)
Geometric Shapes Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 1470 Accepted: 622 D ...
- Geometric Shapes (poj3449多边形相交)
题意:给你一些多边形的点,判断每个多边形和那些多边形相交,编号按照字典序输出 思路:枚举每个多边形的每条边看是否相交,这里的相交是包括端点的,关键是给你正方形不相邻两个点求另外两个点怎么求,长方形给你 ...
- poj3449 Geometric Shapes【计算几何】
含[判断线段相交].[判断两点在线段两侧].[判断三点共线].[判断点在线段上]模板 Geometric Shapes Time Limit: 2000MS Memory Limit: 655 ...
- Inheritance - SGU 129(线段与多边形相交的长度)
题目大意:给一个凸多边形(点不是按顺序给的),然后计算给出的线段在这个凸多边形里面的长度,如果在边界不计算. 分析:WA2..WA3...WA4..WA11...WA的无话可说,总之细节一定考虑清楚, ...
- hdu 5130(2014广州 圆与多边形相交模板)
题意:一个很多个点p构成的多边形,pb <= pa * k时p所占区域与多边形相交面积 设p(x,y), (x - xb)^2+(y - yb)^2 / (x - xa)^2+(y ...
随机推荐
- 流形(Manifold)初步【转】
转载自:http://blog.csdn.net/wangxiaojun911/article/details/17076465 欧几里得几何学(Euclidean Geometry) 两千三百年前, ...
- 创业 CEO:如何选择投资人
欢迎来到「创业 CEO」系列,在这个系列中,我们讨论一个创业者如何教会自己成为一位伟大的 CEO,因为历史上最伟大的创业公司,往往都是由这样的人在领导. AppWorks 成立至今,总共参与投资了 2 ...
- 为SQL Server表中的列添加/修改/删除注释属性(sp_addextendedproperty、sp_updateextendedproperty、sp_dropextendedproperty)
本篇基本完全参考:sql--sp_addextendedproperty和sp_updateextendedproperty (Transact-SQL) 三个存储过程用法一样,以sp_addexte ...
- KMP算法——字符串匹配
正直找工作面试巅峰时期,有幸在学校可以听到July的讲座,在时长将近三个小时的演讲中,发现对于找工作来说,算法数据结构可以算是程序员道路的一个考量吧,毕竟中国学计算机的人太多了,只能使用这些方法来淘汰 ...
- 为什么我们需要使用 touch 命令
为什么我们需要使用 touch 命令 既然 touch 命令描述的是改变时间戳,那么我们可能会想为什么我们需要去改变时间戳呢?这个问题会引发我们的深思.然而,我想有个理由可以解释为什么我们需要使用它. ...
- odoo 错误 Resource interpreted as Stylesheet but transferred with MIME type application/x-css:
odoo8 页面内容显示一半, web 控制台显示错误 Resource interpreted as Stylesheet but transferred with MIME type ap ...
- GPS定位学习笔记
********************************* GPS定位简介 ********************************** 1. iOS SDK提供两个框架来实现位置服务 ...
- init_sequence所对应的函数
一.init_sequence内容 init_fnc_t *init_sequence[] = { cpu_init, /* basic cpu dependent setup */ board_in ...
- For Aisha(阿伊莎)
相见时难别亦难,东风无力百花残.by:昂思多,20160524 跟你在一起,没有拘束感,完全就像是在跟亲人对话. 很喜欢这种感觉 虽然才认识不到10天,却就像是认识了好几年的老朋友 真的喜欢叫你“阿伊 ...
- 使用ListItem给DropDownList填充数据
global::日积月累啥的啊.DBhelper db = new 日积月累啥的啊.DBhelper(); ListItem[] item=]; DataTable dt=db.GetDataTabl ...