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 ...
随机推荐
- 关于left join、right join和inner join
总结, 1.select * from A left join B on A.XX=B.XX 左侧显示A的列名,右侧显示B的列名 左侧,显示A表的所有列 右侧, A.XX=B.XX的时候,显示B表的列 ...
- YTU 2297: KMP模式匹配 三(串)
2297: KMP模式匹配 三(串) 时间限制: 1 Sec 内存限制: 128 MB 提交: 25 解决: 16 [提交][状态][讨论版] [Edit] [TestData] 题目描述 输入一 ...
- c# UDP通信 列子
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- Rigidbody.position/rotation更新测试
Rigidbody.position/rotation主要提供在下一个物理步之前更新物理位置,一般用于SweepTest这样的接口 那么测试一下会不会修改掉transform.position的值 测 ...
- java学习容器
自己模拟ArrayList: private Object[] elementData; private int size; // 可以指定集合大小,默认10 public MyArrayList(i ...
- Android mvp模式、mvvm模式
MVC和MVP的区别2007年08月08日 星期三 上午 09:23 MVC和MVP到底有什么区别呢? 从这幅图可以看到,我们可以看到在MVC里,View是可以直接访问Model的!从而,View里会 ...
- COGS502. 长路上的灯
502. 长路上的灯 ☆ 输入文件:light.in 输出文件:light.out 简单对比时间限制:1 s 内存限制:128 MB [题目描述] 在一条无限长的路上,有一排无限长的路 ...
- (转)jquery对表单元素的取值和赋值
/*获得text的值*/ var textval =$("#text_id").attr("value"); //或者 var textval =$(" ...
- 利用JAVA Service Wrapper把JAVA程序做成windows服务
今天做了一个读取数据入库的程序.由于读取的数据每天都更新,于是就想把程序做成一个服务,每天定时执行.研究了一下,发现有几种方式可以做.下面我主要记录一下JAVA Service Wrapper方式. ...
- ContentProvider官方教程(8)自定义MIME
MIME Type Reference Content providers can return standard MIME media types, or custom MIME type stri ...