链接

繁琐。

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

对于正方形的已知对角顶点求剩余两顶点 (列出4个方程求解)

  1. p[].x=(p[].x+p[].x+p[].y-p[].y)/;
  2. p[].y=(p[].y+p[].y+p[].x-p[].x)/;
  3. p[].x=(p[].x+p[].x-p[].y+p[].y)/;
  4. p[].y=(p[].y+p[].y-p[].x+p[].x)/;
  1. #include <iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<algorithm>
  5. #include<stdlib.h>
  6. #include<vector>
  7. #include<cmath>
  8. #include<queue>
  9. #include<set>
  10. #include<map>
  11. using namespace std;
  12. #define N 600
  13. #define LL long long
  14. #define INF 0xfffffff
  15. #define zero(x) (((x)>0?(x):-(x))<eps)
  16. const double eps = 1e-;
  17. const double pi = acos(-1.0);
  18. const double inf = ~0u>>;
  19. map<string,int>f;
  20. vector<int>ed[];
  21. int g;
  22. struct point
  23. {
  24. double x,y;
  25. point(double x=,double y=):x(x),y(y) {}
  26. } p[];
  27. typedef point pointt;
  28. pointt operator -(point a,point b)
  29. {
  30. return pointt(a.x-b.x,a.y-b.y);
  31. }
  32. struct line
  33. {
  34. pointt u,v;
  35. int flag;
  36. char c;
  37. } li[N];
  38. vector<line>dd[];
  39. char s1[],s2[],s[];
  40. int dcmp(double x)
  41. {
  42. if(fabs(x)<eps) return ;
  43. return x<?-:;
  44. }
  45. point rotate(point a,double rad)
  46. {
  47. return point(a.x*cos(rad)-a.y*sin(rad),a.x*sin(rad)+a.y*cos(rad));
  48. }
  49. double dot(point a,point b)
  50. {
  51. return a.x*b.x+a.y*b.y;
  52. }
  53. double dis(point a)
  54. {
  55. return sqrt(dot(a,a));
  56. }
  57. double angle(point a,point b)
  58. {
  59. return acos(dot(a,b)/dis(a)/dis(b));
  60. }
  61. double cross(point a,point b)
  62. {
  63. return a.x*b.y-a.y*b.x;
  64. }
  65.  
  66. double xmult(point p1,point p2,point p0)
  67. {
  68. return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);
  69. }
  70. //判三点共线
  71. int dots_inline(point p1,point p2,point p3)
  72. {
  73. return zero(xmult(p1,p2,p3));
  74. }
  75.  
  76. //判点是否在线段上,包括端点
  77. int dot_online_in(point p,point l1,point l2)
  78. {
  79. return zero(xmult(p,l1,l2))&&(l1.x-p.x)*(l2.x-p.x)<eps&&(l1.y-p.y)*(l2.y-p.y)<eps;
  80. }
  81.  
  82. //判两点在线段同侧,点在线段上返回0
  83.  
  84. int same_side(point p1,point p2,point l1,point l2)
  85. {
  86. return xmult(l1,p1,l2)*xmult(l1,p2,l2)>eps;
  87. }
  88.  
  89. //判两线段相交,包括端点和部分重合
  90.  
  91. int intersect_in(point u1,point u2,point v1,point v2)
  92. {
  93. if (!dots_inline(u1,u2,v1)||!dots_inline(u1,u2,v2))
  94. return !same_side(u1,u2,v1,v2)&&!same_side(v1,v2,u1,u2);
  95. 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);
  96. }
  97. void init(int kk,char c)
  98. {
  99. int i;
  100. int k = c-'A';
  101. if(kk==)
  102. {
  103. for(i = ; i <= ; i+=)
  104. {
  105. scanf(" (%lf,%lf)",&p[i].x,&p[i].y);
  106. }
  107. p[].x=(p[].x+p[].x+p[].y-p[].y)/;
  108. p[].y=(p[].y+p[].y+p[].x-p[].x)/;
  109. p[].x=(p[].x+p[].x-p[].y+p[].y)/;
  110. p[].y=(p[].y+p[].y-p[].x+p[].x)/;
  111. p[] = p[];
  112. for(i = ; i < ; i++)
  113. {
  114. li[++g].u = p[i];
  115. li[g].v = p[i+];
  116. dd[k].push_back(li[g]);
  117. }
  118. }
  119. else if(kk==)
  120. {
  121. for(i = ; i <= ; i++)
  122. {
  123. scanf(" (%lf,%lf)",&p[i].x,&p[i].y);
  124. }
  125. point pp = point((p[].x+p[].x),(p[].y+p[].y));
  126. p[] = point(pp.x-p[].x,pp.y-p[].y);
  127. //printf("%.3f %.3f\n",p[4].x,p[4].y);
  128. p[] = p[];
  129. for(i = ; i <= ; i++)
  130. {
  131. li[++g].u = p[i];
  132. li[g].v = p[i+];
  133. li[g].c = c;
  134. dd[k].push_back(li[g]);
  135. }
  136. }
  137. else if(kk==)
  138. {
  139. for(i = ; i <= ; i++)
  140. scanf(" (%lf,%lf)",&p[i].x,&p[i].y);
  141. li[++g].u = p[];
  142. li[g].v = p[];
  143. li[g].c = c;
  144. dd[k].push_back(li[g]);
  145. }
  146. else if(kk==)
  147. {
  148. for(i = ; i <= ; i++)
  149. scanf(" (%lf,%lf)",&p[i].x,&p[i].y);
  150. p[] = p[];
  151. for(i = ; i <= ; i++)
  152. {
  153. li[++g].u = p[i];
  154. li[g].v = p[i+];
  155. li[g].c = c;
  156. dd[k].push_back(li[g]);
  157. }
  158. }
  159. else if(kk==)
  160. {
  161. int n;
  162. scanf("%d",&n);
  163. for(i = ; i <= n ; i++)
  164. scanf(" (%lf,%lf)",&p[i].x,&p[i].y);
  165. p[n+] = p[];
  166. for(i = ; i <= n ; i++)
  167. {
  168. li[++g].u= p[i];
  169. li[g].v = p[i+];
  170. li[g].c = c;
  171. dd[k].push_back(li[g]);
  172. }
  173. }
  174. }
  175.  
  176. int main()
  177. {
  178. f["square"] = ;
  179. f["rectangle"] = ;
  180. f["line"] = ;
  181. f["triangle"] = ;
  182. f["polygon"] = ;
  183. int i,j,k;
  184. while(scanf("%s",s1)!=EOF)
  185. {
  186. if(s1[]=='.') break;
  187. if(s1[]=='-') continue;
  188. for(i = ; i < ; i++)
  189. {
  190. ed[i].clear();
  191. dd[i].clear();
  192. }
  193. g = ;
  194. k=;
  195. scanf("%s",s2);
  196. s[++k] = s1[];
  197. init(f[s2],s1[]);
  198. while(scanf("%s",s1)!=EOF)
  199. {
  200. if(s1[]=='-') break;
  201. //cout<<s1<<endl;
  202. scanf("%s",s2);
  203. s[++k] = s1[];
  204. init(f[s2],s1[]);
  205. }
  206. //cout<<g<<endl;
  207. sort(s+,s+k+);
  208. for(i = ; i <= k; i++)
  209. {
  210. int u,v;
  211. u = s[i]-'A';
  212. //cout<<u<<" "<<dd[u].size()<<endl;
  213. for(j = i+; j <= k ; j++)
  214. {
  215. v = s[j]-'A';
  216. int flag = ;
  217. for(int ii = ; ii < dd[u].size() ; ii++)
  218. {
  219. for(int jj = ; jj < dd[v].size() ; jj++)
  220. {
  221. if(intersect_in(dd[u][ii].u,dd[u][ii].v,dd[v][jj].u,dd[v][jj].v))
  222. {
  223.  
  224. flag = ;
  225. break;
  226. }
  227. // if(u==5&&v==22)
  228. // {
  229. // output(dd[u][ii].u);
  230. // output(dd[u][ii].v);
  231. // output(dd[v][jj].u);
  232. // output(dd[v][jj].v);
  233. // }
  234. }
  235. if(flag) break;
  236. }
  237. if(flag)
  238. {
  239. ed[u].push_back(v);
  240. ed[v].push_back(u);
  241. }
  242. }
  243. }
  244. for(i = ; i <= k; i++)
  245. {
  246. int u = s[i]-'A';
  247. if(ed[u].size()==)
  248. printf("%c has no intersections\n",s[i]);
  249. else
  250. {
  251.  
  252. sort(ed[u].begin(),ed[u].end());
  253. if(ed[u].size()==)
  254. printf("%c intersects with %c\n",s[i],ed[u][]+'A');
  255. else if(ed[u].size()==)
  256. printf("%c intersects with %c and %c\n",s[i],ed[u][]+'A',ed[u][]+'A');
  257. else
  258. {
  259. printf("%c intersects with ",s[i]);
  260. for(j = ; j < ed[u].size()- ; j++)
  261. printf("%c, ",ed[u][j]+'A');
  262. printf("and %c\n",ed[u][j]+'A');
  263. }
  264. }
  265. }
  266. puts("");
  267. }
  268. return ;
  269. }

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. northwind数据库

    ① Categories: 种类表相应字段:CategoryID :类型ID:CategoryName:类型名;Description:类型说明;Picture:产品样本 ② CustomerCust ...

  2. 20145227 《Java程序设计》第3周学习总结

    20145227 <Java程序设计>第3周学习总结 教材学习内容总结 第四章 认识对象 4.1 类与对象 1.定义类:生活中描述事物无非就是描述事物的属性和行为.如:人有身高,体重等属性 ...

  3. Spring框架bean的配置(3):基于注解的配置

    1.基于注解的配置: @Component: 基本注解, 标识了一个受 Spring 管理的组件 @Respository: 标识持久层组件 @Service: 标识服务层(业务层)组件 @Contr ...

  4. Poj(1325),最小点覆盖

    题目链接:http://poj.org/problem?id=1325 Machine Schedule Time Limit: 1000MS   Memory Limit: 10000K Total ...

  5. C#中另类自定义公式计算 字符串转换为计算公式,并得出计算结果

    [csharp] view plain copy print? //方法一 利用DataTable中的Compute方法 例如:1*2-(4/1)+2*4=6 , , , ); DataTable d ...

  6. 源码安装python

    编译安装新版本python 一般来说python是linux系统的标配,但是版本一般却很老,而系统上面的很多服务可能与老的python存在依赖关系,我们又不能直接卸载.所以一般,我们可以在一个单独的目 ...

  7. stm32中断服务函数

    你打开stm32的启动文件,例如startup_stm32f10x_hd.s 里面有很多中断跳转的入口.用白话说就是固件库帮你写好了发生什么中断时跳转到哪里,这些名字是一个函数名,你要把这些函数写出来 ...

  8. centos 安装 mysql 5.6和workbench

    windows下安装mysql很简单,去官网找到.msi文件,一键安装就OK了. Centos下面安装Mysql5.6其实也是蛮简单的. 注意:centos6.5默认mysql版本是5.1的 1.添加 ...

  9. SqlSever基础 rtrim函数 除去字符串的右边的空格,左边中间的不管

    镇场诗:---大梦谁觉,水月中建博客.百千磨难,才知世事无常.---今持佛语,技术无量愿学.愿尽所学,铸一良心博客.------------------------------------------ ...

  10. qt 3 获取文件路径中的一部分

    QList<QString> qlist = path.split(QRegExp("[\\\\/]")); QString FileName = qlist.at(q ...