FZU2273Triangles+(三角形)+第八届福建省大学生程序设计竞赛
来源:互联网 发布:mac怎么更新系统 编辑:程序博客网 时间:2024/05/20 22:26
Problem 2273 Triangles
Accept: 47 Submit: 115
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
20 0 0 1 1 0 10 10 9 9 9 100 0 1 1 1 0 0 0 1 1 0 1
Sample Output
disjoint intersect
Source
第八届福建省大学生程序设计竞赛-重现赛(感谢承办方厦门理工学院)模板题
题意
给你两个三角形,判断是相交分离还是包含
思路
首先判断两个三角形是否相交,去判断边是否相交 http://blog.csdn.net/hyyjiushiliangxing/article/details/76010706
然后判断包含还是分离,去判断点在三角形内还是外 http://blog.csdn.net/hyyjiushiliangxing/article/details/76012954
#include<stdio.h> #include <iostream> #include <math.h> using namespace std; #define ABS_FLOAT_0 0.0001 double 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; } } if(flag) { printf("contain\n"); continue; } else printf("disjoint\n"); } return 0; }
阅读全文
0 0
- FZU2273Triangles+(三角形)+第八届福建省大学生程序设计竞赛
- 第八届福建省大学生程序设计竞赛
- 2017第八届福建省大学生程序设计竞赛总结
- 第八届福建省大学生程序设计竞赛训练总结【7/12】
- 第八届福建省大学生程序设计竞赛 D.Game【思维+KMP】
- 第八届福建省大学生程序设计竞赛-重现赛 A Frog
- 第八届福建省大学生程序设计竞赛-重现赛I Magic
- 7.22.17 第八届福建省大学生程序设计竞赛-重现赛
- 第八届福建省大学生程序设计竞赛 G.YYS【期望+大数】
- FZU2272+Frog+签到题+第八届福建省大学生程序设计竞赛
- 第八届福建省大学生程序设计竞赛 省赛回忆
- 第八届福建省大学生程序设计竞赛-K Wand(错位+组合数)
- 第八届福建省大学生程序设计竞赛 2280 Magic (字符串hash)
- 第八届福建省大学生程序设计竞赛-重现赛(感谢承办方厦门理工学院)
- 第六届福建省大学生程序设计竞赛(FZU2212—FZU2221)
- 第六届福建省大学生程序设计竞赛(几道水题)
- 第四届福建省大学生程序设计竞赛
- 第六届福建省大学生程序设计竞赛
- 17-7-24周总结(Python教程笔记)
- 【python 】数据类型和返回数据类型的函数
- bootstrap的验证插件
- ros 创建自己的msg srv 注意
- 移动端 显示滚动条
- FZU2273Triangles+(三角形)+第八届福建省大学生程序设计竞赛
- 无锁队列-使用hazard指针解决ABA问题
- 嵌入式Linux进程信息及内存布局
- Linux基本认识
- Android图表achartengine、MPAndroidChart之菜鸟篇
- 数据类型及其位数区别
- 一张图说明CDN网络的原理
- 数据库
- poj3659 Cell Phone Network(树形dp)