链接

繁琐。

处理出来所有的线段,再判断相交。

对于正方形的已知对角顶点求剩余两顶点 (列出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的更多相关文章

  1. 十二、shapes

    1. The control points are attributes on the shape which are usually arrays of points. Control points ...

  2. Allegro Out Of Date Shapes原因及解决方法

    使用Allegro设计PCB板时,查看Status,经常会遇到out of date shapes的警告信息,具体如下: dynamic shape is still out of data or e ...

  3. Topology Shapes of OpenCascade BRep

    Topology Shapes of OpenCascade BRep eryar@163.com 摘要Abstract:通过对OpenCascade中的BRep数据的读写,理解边界表示法的概念及实现 ...

  4. graphviz - Node Shapes

    Node Shapes There are three main types of shapes : polygon-based, record-based and user-defined. The ...

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

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

  6. Geometric Shapes - POJ 3449(多边形相交)

    题目大意:给一些几何图形的编号,求出来这些图形都和那些相交.   分析:输入的正方形对角线上的两个点,所以需要求出来另外两个点,公式是: x2:=(x1+x3+y3-y1)/2; y2:=(y1+y3 ...

  7. 详细分析Orchard的Content、Drivers, Shapes and Placement 类型

    本文原文来自:http://skywalkersoftwaredevelopment.net/blog/a-closer-look-at-content-types-drivers-shapes-an ...

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

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

  9. 解决gerber-Failed to Match All Shapes for PCB问题

    有效解决在Protel 99se导gerber时提示gerber-Failed to Match All Shapes for PCB出错问题如图 这种问题很好解决,打开这个窗口 操作方法如下图Emb ...

随机推荐

  1. 超文本标记语言(HTML)

    超文本标记语言(HyperText MarkUp Language,HTML) HTML是用来制作网页的标记语言,HTML不需要编译,直接由浏览器解析: HTML文件是一个文本文件,包含了一些HTML ...

  2. 发现数据库错误模式(AppScan扫描结果)

    最近工作要求解决下web的项目的漏洞问题,扫描漏洞是用的AppScan工具,其中此篇文章是关于发现数据库错误模式问题的.下面就把这块东西分享出来. 原创文章,转载请注明 --------------- ...

  3. 会话标识未更新(AppScan扫描结果)

    最近工作要求解决下web的项目的漏洞问题,扫描漏洞是用的AppScan工具,其中此篇文章是关于会话标识未更新问题的.下面就把这块东西分享出来. 原创文章,转载请注明 ----------------- ...

  4. Unity-Animator深入系列---FAQ

    回到 Animator深入系列总目录 Q: 如果想做角色负伤的一套动画,但是又和原有状态机不冲突,只是想换动画剪辑,应该怎么办? A: 新建一个层,设置为同步模式.这时候你不能在同步层添加状态,但你可 ...

  5. noi 8465 马走日

    8465:马走日 查看 提交 统计 提问 总时间限制:  1000ms 内存限制:  1024kB 描述 马在中国象棋以日字形规则移动. 请编写一段程序,给定n*m大小的棋盘,以及马的初始位置(x,y ...

  6. WinMain函数详解(转载)

    略加增添与修改! 工具:VC++6.0       系统:win7 64位 在Windows应用程序中,我们可以认为 WinMain() 函数是程序的入口,WinMain()的原型如下: int WI ...

  7. 2014江西理工大学C语言程序竞赛初级组

    坐公交 解法:略 #include<stdio.h> #include<string> #include<iostream> #include<math.h& ...

  8. qbxt十一系列二

    PA[题目描述]汉诺塔升级了:现在我们有N个圆盘和N个柱子,每个圆盘大小都不一样,大的圆盘不能放在小的圆盘上面,N个柱子从左到右排成一排.每次你可以将一个柱子上的最上面的圆盘移动到右边或者左边的柱子上 ...

  9. reactnativemodal

    'use strict'; var React = require('react-native'); var Modal = require('react-native-modal'); var { ...

  10. Objective-C学习笔记_命令行参数获取

    找到编译目录下执行myapp >./myapp param1 param2 在应用中可以这样来获取param1/param2 NSProcessInfo *proc = [NSProcessIn ...