poj3449Geometric Shapes
繁琐。
处理出来所有的线段,再判断相交。
对于正方形的已知对角顶点求剩余两顶点 (列出4个方程求解)
p[].x=(p[].x+p[].x+p[].y-p[].y)/;
p[].y=(p[].y+p[].y+p[].x-p[].x)/;
p[].x=(p[].x+p[].x-p[].y+p[].y)/;
p[].y=(p[].y+p[].y-p[].x+p[].x)/;
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
#include<map>
using namespace std;
#define N 600
#define LL long long
#define INF 0xfffffff
#define zero(x) (((x)>0?(x):-(x))<eps)
const double eps = 1e-;
const double pi = acos(-1.0);
const double inf = ~0u>>;
map<string,int>f;
vector<int>ed[];
int g;
struct point
{
double x,y;
point(double x=,double y=):x(x),y(y) {}
} p[];
typedef point pointt;
pointt operator -(point a,point b)
{
return pointt(a.x-b.x,a.y-b.y);
}
struct line
{
pointt u,v;
int flag;
char c;
} li[N];
vector<line>dd[];
char s1[],s2[],s[];
int dcmp(double x)
{
if(fabs(x)<eps) return ;
return x<?-:;
}
point rotate(point a,double rad)
{
return point(a.x*cos(rad)-a.y*sin(rad),a.x*sin(rad)+a.y*cos(rad));
}
double dot(point a,point b)
{
return a.x*b.x+a.y*b.y;
}
double dis(point a)
{
return sqrt(dot(a,a));
}
double angle(point a,point b)
{
return acos(dot(a,b)/dis(a)/dis(b));
}
double cross(point a,point b)
{
return a.x*b.y-a.y*b.x;
} double xmult(point p1,point p2,point p0)
{
return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);
}
//判三点共线
int dots_inline(point p1,point p2,point p3)
{
return zero(xmult(p1,p2,p3));
} //判点是否在线段上,包括端点
int dot_online_in(point p,point l1,point l2)
{
return zero(xmult(p,l1,l2))&&(l1.x-p.x)*(l2.x-p.x)<eps&&(l1.y-p.y)*(l2.y-p.y)<eps;
} //判两点在线段同侧,点在线段上返回0 int same_side(point p1,point p2,point l1,point l2)
{
return xmult(l1,p1,l2)*xmult(l1,p2,l2)>eps;
} //判两线段相交,包括端点和部分重合 int intersect_in(point u1,point u2,point v1,point v2)
{
if (!dots_inline(u1,u2,v1)||!dots_inline(u1,u2,v2))
return !same_side(u1,u2,v1,v2)&&!same_side(v1,v2,u1,u2);
return dot_online_in(u1,v1,v2)||dot_online_in(u2,v1,v2)||dot_online_in(v1,u1,u2)||dot_online_in(v2,u1,u2);
}
void init(int kk,char c)
{
int i;
int k = c-'A';
if(kk==)
{
for(i = ; i <= ; i+=)
{
scanf(" (%lf,%lf)",&p[i].x,&p[i].y);
}
p[].x=(p[].x+p[].x+p[].y-p[].y)/;
p[].y=(p[].y+p[].y+p[].x-p[].x)/;
p[].x=(p[].x+p[].x-p[].y+p[].y)/;
p[].y=(p[].y+p[].y-p[].x+p[].x)/;
p[] = p[];
for(i = ; i < ; i++)
{
li[++g].u = p[i];
li[g].v = p[i+];
dd[k].push_back(li[g]);
}
}
else if(kk==)
{
for(i = ; i <= ; i++)
{
scanf(" (%lf,%lf)",&p[i].x,&p[i].y);
}
point pp = point((p[].x+p[].x),(p[].y+p[].y));
p[] = point(pp.x-p[].x,pp.y-p[].y);
//printf("%.3f %.3f\n",p[4].x,p[4].y);
p[] = p[];
for(i = ; i <= ; i++)
{
li[++g].u = p[i];
li[g].v = p[i+];
li[g].c = c;
dd[k].push_back(li[g]);
}
}
else if(kk==)
{
for(i = ; i <= ; i++)
scanf(" (%lf,%lf)",&p[i].x,&p[i].y);
li[++g].u = p[];
li[g].v = p[];
li[g].c = c;
dd[k].push_back(li[g]);
}
else if(kk==)
{
for(i = ; i <= ; i++)
scanf(" (%lf,%lf)",&p[i].x,&p[i].y);
p[] = p[];
for(i = ; i <= ; i++)
{
li[++g].u = p[i];
li[g].v = p[i+];
li[g].c = c;
dd[k].push_back(li[g]);
}
}
else if(kk==)
{
int n;
scanf("%d",&n);
for(i = ; i <= n ; i++)
scanf(" (%lf,%lf)",&p[i].x,&p[i].y);
p[n+] = p[];
for(i = ; i <= n ; i++)
{
li[++g].u= p[i];
li[g].v = p[i+];
li[g].c = c;
dd[k].push_back(li[g]);
}
}
} int main()
{
f["square"] = ;
f["rectangle"] = ;
f["line"] = ;
f["triangle"] = ;
f["polygon"] = ;
int i,j,k;
while(scanf("%s",s1)!=EOF)
{
if(s1[]=='.') break;
if(s1[]=='-') continue;
for(i = ; i < ; i++)
{
ed[i].clear();
dd[i].clear();
}
g = ;
k=;
scanf("%s",s2);
s[++k] = s1[];
init(f[s2],s1[]);
while(scanf("%s",s1)!=EOF)
{
if(s1[]=='-') break;
//cout<<s1<<endl;
scanf("%s",s2);
s[++k] = s1[];
init(f[s2],s1[]);
}
//cout<<g<<endl;
sort(s+,s+k+);
for(i = ; i <= k; i++)
{
int u,v;
u = s[i]-'A';
//cout<<u<<" "<<dd[u].size()<<endl;
for(j = i+; j <= k ; j++)
{
v = s[j]-'A';
int flag = ;
for(int ii = ; ii < dd[u].size() ; ii++)
{
for(int jj = ; jj < dd[v].size() ; jj++)
{
if(intersect_in(dd[u][ii].u,dd[u][ii].v,dd[v][jj].u,dd[v][jj].v))
{ flag = ;
break;
}
// if(u==5&&v==22)
// {
// output(dd[u][ii].u);
// output(dd[u][ii].v);
// output(dd[v][jj].u);
// output(dd[v][jj].v);
// }
}
if(flag) break;
}
if(flag)
{
ed[u].push_back(v);
ed[v].push_back(u);
}
}
}
for(i = ; i <= k; i++)
{
int u = s[i]-'A';
if(ed[u].size()==)
printf("%c has no intersections\n",s[i]);
else
{ sort(ed[u].begin(),ed[u].end());
if(ed[u].size()==)
printf("%c intersects with %c\n",s[i],ed[u][]+'A');
else if(ed[u].size()==)
printf("%c intersects with %c and %c\n",s[i],ed[u][]+'A',ed[u][]+'A');
else
{
printf("%c intersects with ",s[i]);
for(j = ; j < ed[u].size()- ; j++)
printf("%c, ",ed[u][j]+'A');
printf("and %c\n",ed[u][j]+'A');
}
}
}
puts("");
}
return ;
}
poj3449Geometric Shapes的更多相关文章
- 十二、shapes
1. The control points are attributes on the shape which are usually arrays of points. Control points ...
- Allegro Out Of Date Shapes原因及解决方法
使用Allegro设计PCB板时,查看Status,经常会遇到out of date shapes的警告信息,具体如下: dynamic shape is still out of data or e ...
- Topology Shapes of OpenCascade BRep
Topology Shapes of OpenCascade BRep eryar@163.com 摘要Abstract:通过对OpenCascade中的BRep数据的读写,理解边界表示法的概念及实现 ...
- graphviz - Node Shapes
Node Shapes There are three main types of shapes : polygon-based, record-based and user-defined. The ...
- POJ 3449 Geometric Shapes(判断几个不同图形的相交,线段相交判断)
Geometric Shapes Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 1243 Accepted: 524 D ...
- Geometric Shapes - POJ 3449(多边形相交)
题目大意:给一些几何图形的编号,求出来这些图形都和那些相交. 分析:输入的正方形对角线上的两个点,所以需要求出来另外两个点,公式是: x2:=(x1+x3+y3-y1)/2; y2:=(y1+y3 ...
- 详细分析Orchard的Content、Drivers, Shapes and Placement 类型
本文原文来自:http://skywalkersoftwaredevelopment.net/blog/a-closer-look-at-content-types-drivers-shapes-an ...
- POJ 3449 Geometric Shapes (求正方形的另外两点)
Geometric Shapes Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 1470 Accepted: 622 D ...
- 解决gerber-Failed to Match All Shapes for PCB问题
有效解决在Protel 99se导gerber时提示gerber-Failed to Match All Shapes for PCB出错问题如图 这种问题很好解决,打开这个窗口 操作方法如下图Emb ...
随机推荐
- ACM题目————一笔画问题
描述 zyc从小就比较喜欢玩一些小游戏,其中就包括画一笔画,他想请你帮他写一个程序,判断一个图是否能够用一笔画下来. 规定,所有的边都只能画一次,不能重复画. 输入 第一行只有一个正整数N(N< ...
- gets()和getchar()还有getch()的区别
getch()和getchar()区别:1.getch(): 所在头文件:conio.h 函数用途:从控制台读取一个字符,但不显示在屏幕上例如: char ch;或int ch: getch();或c ...
- 使用VisualSVN建立SVN Server
首先去官网下载安装包.http://subversion.apache.org/packages.html找到windows的,选择VisualSVN->VISUALSVN SERVER 双击开 ...
- hdu4940 Destroy Transportation system(2014多校联合第七场)
题意很容易转化到这样的问题:在一个强连通的有向图D中是否存在这样的集合划分S + T = D,从S到T集合的边权大于从T到S集合的边权. 即D(i, j) > B(j, i) + D(j, i ...
- Find them, Catch them
Find them, Catch them Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 36488 Accepted: 111 ...
- Paratroopers
Paratroopers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7881 Accepted: 2373 Descript ...
- Discuz! 6.x/7.x 全局变量防御绕过导致命令执行
https://www.secpulse.com/archives/2338.html 模拟register_globals功能的代码,在GPC为off时会调用addslashes()函数处理变量值, ...
- Java 期末复习提纲
Java 开发环境 Java 的特点 面向对象.跨平台.能把中小型程序写成大型程序 开发 Java 的流程 设计类 写代码 重构 Java 程序规范 Javadoc 风格注释 接口以 able 结尾 ...
- SharePoint自动化系列——创建MMS terms
转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ PowerShell脚本实现MMS group.termSet.terms的自动化创建: Add- ...
- Java中HashMap遍历的两种方式
Java中HashMap遍历的两种方式 转]Java中HashMap遍历的两种方式原文地址: http://www.javaweb.cc/language/java/032291.shtml 第一种: ...