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 ...
随机推荐
- northwind数据库
① Categories: 种类表相应字段:CategoryID :类型ID:CategoryName:类型名;Description:类型说明;Picture:产品样本 ② CustomerCust ...
- 20145227 《Java程序设计》第3周学习总结
20145227 <Java程序设计>第3周学习总结 教材学习内容总结 第四章 认识对象 4.1 类与对象 1.定义类:生活中描述事物无非就是描述事物的属性和行为.如:人有身高,体重等属性 ...
- Spring框架bean的配置(3):基于注解的配置
1.基于注解的配置: @Component: 基本注解, 标识了一个受 Spring 管理的组件 @Respository: 标识持久层组件 @Service: 标识服务层(业务层)组件 @Contr ...
- Poj(1325),最小点覆盖
题目链接:http://poj.org/problem?id=1325 Machine Schedule Time Limit: 1000MS Memory Limit: 10000K Total ...
- C#中另类自定义公式计算 字符串转换为计算公式,并得出计算结果
[csharp] view plain copy print? //方法一 利用DataTable中的Compute方法 例如:1*2-(4/1)+2*4=6 , , , ); DataTable d ...
- 源码安装python
编译安装新版本python 一般来说python是linux系统的标配,但是版本一般却很老,而系统上面的很多服务可能与老的python存在依赖关系,我们又不能直接卸载.所以一般,我们可以在一个单独的目 ...
- stm32中断服务函数
你打开stm32的启动文件,例如startup_stm32f10x_hd.s 里面有很多中断跳转的入口.用白话说就是固件库帮你写好了发生什么中断时跳转到哪里,这些名字是一个函数名,你要把这些函数写出来 ...
- centos 安装 mysql 5.6和workbench
windows下安装mysql很简单,去官网找到.msi文件,一键安装就OK了. Centos下面安装Mysql5.6其实也是蛮简单的. 注意:centos6.5默认mysql版本是5.1的 1.添加 ...
- SqlSever基础 rtrim函数 除去字符串的右边的空格,左边中间的不管
镇场诗:---大梦谁觉,水月中建博客.百千磨难,才知世事无常.---今持佛语,技术无量愿学.愿尽所学,铸一良心博客.------------------------------------------ ...
- qt 3 获取文件路径中的一部分
QList<QString> qlist = path.split(QRegExp("[\\\\/]")); QString FileName = qlist.at(q ...