2017acm福建省赛FZU 2273 Triangles
来源:互联网 发布:js format 编辑:程序博客网 时间:2024/05/16 14:14
Problem 2273 Triangles
Accept: 34 Submit: 82
Time Limit: 1000 mSec Memory Limit : 262144 KB
Problem Description
This is a simple problem. Given two triangles A and B, you should determine they are intersect, contain or disjoint. (Public edge or point are treated as intersect.)
Input
First line contains an integer T (1 ≤ T ≤ 10), represents there are T test cases.
For each test case: X1 Y1 X2 Y2 X3 Y3 X4 Y4 X5 Y5 X6 Y6. All the coordinate are integer. (X1,Y1) , (X2,Y2), (X3,Y3) forms triangles A ; (X4,Y4) , (X5,Y5), (X6,Y6) forms triangles B.
-10000<=All the coordinate <=10000
Output
For each test case, output “intersect”, “contain” or “disjoint”.
Sample Input
2
0 0 0 1 1 0 10 10 9 9 9 10
0 0 1 1 1 0 0 0 1 1 0 1
Sample Output
disjoint
intersect
Source
第八届福建省大学生程序设计竞赛-重现赛(感谢承办方厦门理工学院)http://acm.fzu.edu.cn/problem.php?pid=2273
判断两个三角形是 内含 还是相交 还是分离什么都不说 直接上模板吧
#include<stdio.h>#include <iostream>#include <math.h>using namespace std;#define ABS_FLOAT_0 0.0001double xx[88],yy[88];struct node{ double x, y;} st1, ed1, st2, ed2;struct point_float{ float x; float y;};double get_area(node a0, node a1, node a2) //求有向面积{ double s = a0.x*a1.y + a2.x*a0.y +a1.x*a2.y - a2.x*a1.y - a0.x*a2.y - a1.x*a0.y; return s;}float GetTriangleSquar(const point_float pt0, const point_float pt1, const point_float pt2){ point_float AB, BC; AB.x = pt1.x - pt0.x; AB.y = pt1.y - pt0.y; BC.x = pt2.x - pt1.x; BC.y = pt2.y - pt1.y; return fabs((AB.x * BC.y - AB.y * BC.x)) / 2.0f;}bool IsInTriangle(const point_float A, const point_float B, const point_float C, const point_float D){ float SABC, SADB, SBDC, SADC; SABC = GetTriangleSquar(A, B, C); SADB = GetTriangleSquar(A, D, B); SBDC = GetTriangleSquar(B, D, C); SADC = GetTriangleSquar(A, D, C); float SumSuqar = SADB + SBDC + SADC; if ((-ABS_FLOAT_0 < (SABC - SumSuqar)) && ((SABC - SumSuqar) < ABS_FLOAT_0)) { return true; } else { return false; }}int pd(){ double s1 = get_area(st1, ed1, st2); double s2 = get_area(st1, ed1, ed2); double s3 = get_area(st2, ed2, st1); double s4 = get_area(st2, ed2, ed1); if(s1 * s2 <= 0 && s3 * s4 <= 0) return 1; //printf("Interseetion\n"); else return 0; //printf("Not Interseetion\n");}int main(){ int t,flag,i,j,k,h; scanf("%d",&t); while(t--) { scanf("%lf %lf %lf %lf %lf %lf",&xx[1],&yy[1],&xx[2],&yy[2],&xx[3],&yy[3]); scanf("%lf %lf %lf %lf %lf %lf",&xx[4],&yy[4],&xx[5],&yy[5],&xx[6],&yy[6]); flag=0; for(i=1; i<=3; i++) { st1.x=xx[i]; st1.y=yy[i]; for(k=1; k<=3; k++) { if(k!=i) { ed1.x=xx[k]; ed1.y=yy[k]; for(j=4; j<=6; j++) { st2.x=xx[j]; st2.y=yy[j]; for(h=4; h<=6; h++) { if(h!=j) { ed2.x=xx[h]; ed2.y=yy[h]; if(pd()) { flag=1; break; } } } } } } } //利用两线段是否相交 判断三角形是否相交 if(flag) { printf("intersect\n"); continue; } point_float A, B, C, P; A.x =xx[1]; A.y =yy[1] ; B.x =xx[2] ; B.y =yy[2] ; C.x =xx[3] ; C.y =yy[3] ; //判断三个点是否在三角形内 for(i=4; i<=6; i++) { P.x=xx[i]; P.y=yy[i]; if(IsInTriangle(A, B, C, P)) { flag=1; break; } } //再判断A在B里面吗 A.x =xx[4]; A.y =yy[4] ; B.x =xx[5] ; B.y =yy[5] ; C.x =xx[6] ; C.y =yy[6] ; //判断三个点是否在三角形内 for(i=1; i<=3; i++) { P.x=xx[i]; P.y=yy[i]; if(IsInTriangle(A, B, C, P)) { flag=1; break; } } if(flag) { printf("contain\n"); continue; } else printf("disjoint\n"); } return 0;}
阅读全文
0 0
- 2017acm福建省赛FZU 2273 Triangles
- 2017acm福建省赛FZU 2278 YYS
- 2017年福建省赛 FZU
- 第八届福建省大学生程序设计竞赛 FZU 2273 Triangles (计算几何)
- 2017acm福建省赛FZU2272 Frog
- fzu 2273 Triangles 计算几何
- 2017福建省赛Problem B Triangles(判断两三角形位置关系)
- Triangles FZU
- 2017ACM福建省赛FZU2283 Tic-Tac-Toe
- 2013年福建省赛ACM题目
- ACM 福建省省赛 D题 Game
- 第七届福建省赛 FZU 2267 X(floyd)
- Two Triangles FZU
- 第八届福建省大学生程序设计竞赛 重现赛 第二题 Triangles
- 2017福建省赛FZU2282 Wand
- 2011福建省ACM省赛暨福州区域赛晋级赛总结
- FZU Problem 2221 RunningMan(思维考查)——第六届福建省大学生程序设计竞赛-重现赛
- 第七届福建省赛 FZU 2267 The Bigger the Better(贪心 后缀数组)
- 如何修改maven镜像为阿里云
- 十、声明式 REST 客户端-Feign 的高级特性
- 纯CSS实现小车动画
- 赌徒
- SQL入门经典-总体概括
- 2017acm福建省赛FZU 2273 Triangles
- #include <stdio.h> struct student { char name[21]; int cj[2]; //cj[0]表示期末成绩,cj[1]表示班级评议成绩 char ch[2]
- 使用Git时文件的生命周期和工作流程
- Windows PowerShell 实战指南-动手实验-3.8
- Redis主从复制
- input和raw_inpt
- SoftMax原理及代码
- shadowocks的搭建与配置
- VirtualBox虚拟机上CentOS 6.3的建立