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
判断两个三角形是 相交,包含,还是相离的关系
包含关系:
如图:若ΔDEF被包含;则可通过点来判断
D点被包含SΔACD+SΔCDB+SΔADB=SΔABC 同理判断E、F点,若三点全满足则包含
相离关系:
如图:若D点在外:则有SΔDAC+SΔDBC+SΔAB>SΔABC
若三点都满足上式,则相离,剩下的就只有相交关系了。
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <cstring>
  4. #include <cstdio>
  5. #include <vector>
  6. #include <iomanip>
  7. #include <cmath>
  8. #include <ctime>
  9. #include <map>
  10. #include <set>
  11. using namespace std;
  12. #define lowbit(x) (x&(-x))
  13. #define max(x,y) (x>y?x:y)
  14. #define min(x,y) (x<y?x:y)
  15. #define MAX 100000000000000000
  16. #define MOD 1000000007
  17. #define pi acos(-1.0)
  18. #define ei exp(1)
  19. #define PI 3.141592653589793238462
  20. #define INF 0x3f3f3f3f3f
  21. #define mem(a) (memset(a,0,sizeof(a)))
  22. typedef long long ll;
  23. int t,ans;
  24. struct point
  25. {
  26. double x;
  27. double y;
  28. };
  29. struct trangle
  30. {
  31. point p[];
  32. }angle[];
  33. double area(point a,point b,point c)
  34. {
  35. return fabs((b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y));//三角形面积
  36. }
  37. bool check(trangle a,trangle b)
  38. {
  39. double area_trangle=area(a.p[],a.p[],a.p[]);//判断是否包含和不相交
  40. int pos=;
  41. for(int i=;i<;i++)
  42. {
  43. if((area(b.p[i],a.p[],a.p[])+area(b.p[i],a.p[],a.p[])+area(b.p[i],a.p[],a.p[]))>area_trangle) continue;
  44. else ans++,pos++;
  45. }
  46. return pos==;
  47. }
  48. void solve()
  49. {
  50. ans=;
  51. if(check(angle[],angle[]) || check(angle[],angle[]))
  52. {
  53. puts("contain");
  54. return ;
  55. }
  56. else if(!ans)
  57. {
  58. puts("disjoint");
  59. return ;
  60. }
  61. else
  62. {
  63. puts("intersect");
  64. return ;
  65. }
  66. }
  67. int main()
  68. {
  69. scanf("%d",&t);
  70. while(t--)
  71. {
  72. for(int i=;i<;i++)
  73. {
  74. for(int j=;j<;j++)
  75. {
  76. scanf("%lf%lf",&angle[i].p[j].x,&angle[i].p[j].y);
  77. }
  78. }
  79. solve();
  80. }
  81. return ;
  82. }

福建省第八届 Triangles的更多相关文章

  1. FZU 2273 Triangles 第八届福建省赛 (三角形面积交 有重边算相交)

    Problem Description This is a simple problem. Given two triangles A and B, you should determine they ...

  2. FZU 2272 Frog 第八届福建省赛 (鸡兔同笼水题)

    Problem Description Therearex frogs and y chicken in a garden. Kim found there are n heads and m leg ...

  3. FOJ Problem 2273 Triangles

    Problem 2273 Triangles Accept: 201    Submit: 661Time Limit: 1000 mSec    Memory Limit : 262144 KB P ...

  4. FZUOJ-2273 Triangles

     Problem 2273 Triangles Accept: 109    Submit: 360 Time Limit: 1000 mSec    Memory Limit : 262144 KB ...

  5. Count the number of possible triangles

    From: http://www.geeksforgeeks.org/find-number-of-triangles-possible/ Given an unsorted array of pos ...

  6. 电子科技大学第八届ACM趣味程序设计竞赛第四场(正式赛)题解

    A. Picking&Dancing 有一列n个石子,两人交替取石子,每次只能取连续的两个,取走后,剩下的石子仍然排成1列.问最后剩下的石子数量是奇数还是偶数. 读懂题意就没什么好说的. #i ...

  7. [ACM_搜索] Triangles(POJ1471,简单搜索,注意细节)

    Description It is always very nice to have little brothers or sisters. You can tease them, lock them ...

  8. acdream.Triangles(数学推导)

    Triangles Time Limit:1000MS     Memory Limit:64000KB     64bit IO Format:%lld & %llu Submit Stat ...

  9. UVA 12651 Triangles

    You will be given N points on a circle. You must write a program to determine how many distinctequil ...

随机推荐

  1. 关于Github Pages

    迁移Github Pages 我稍微有一点强迫症,实在是忍受不了整洁的界面有一些推广的广告.正所谓博客平台不重要,重要的是要有干货,CSDN首页满屏的广告也就忍受了,但是自己的文章的页面有广告看着实在 ...

  2. elasticsearch搜索类型简单介绍

    简单搜索 GET请求很easy--你能轻松获取你想要的文档.让我们来进一步尝试一些东西.比方简单的搜索! 我们尝试一个最简单的搜索所有员工的请求: GET /megacorp/employee/_se ...

  3. Android控件-单选按钮RadioButton

    RadioGroup单选按钮用法,还是先看效果图 先中后,点RadioGroup测试按钮,可在标题栏显示选择结果,点清除可以清除选择.下面上代码,main.xml: <RadioGroup an ...

  4. js实现导出数据到excel

    来自:http://www.imooc.com/article/13374 //html代码<!DOCTYPE HTML> <html> <head> <ti ...

  5. BFS(广度优先搜索)

    Catch That Cow Farmer John has been informed of the location of a fugitive cow and wants to catch he ...

  6. Chromium String usage

    For Developers‎ > ‎ Chromium String usage Types of StringsIn the Chromium code base, we use std:: ...

  7. 新手教程:电信+广电(或其他运营商)双WAN设置

    由于国内不同运营商之间互联互通存在问题,假如用联通的线路去访问电信的站点那么会比较卡,反之亦然:所以如果两个WAN的线路不是同一个运营商,一般都是建议用户双WAN模式选为“智能路由”.经过本人测试发现 ...

  8. 微信小程序官方文档中的加密算法

    用Nodejs来算一下:

  9. js获取当前时间年份,处理年月日

    js中获得当前时间年份.月份.日期       //获取完整的日期 var date=new Date; var y = date.getFullYear()var m = date.getMonth ...

  10. 开发板ping得通本地,但是不能上网

    在3531D的开发板上面接入LAN7500的USB转以太网口,加载完驱动后. 然后开启eth1 查看一下ifconfig,发现没有ip,配置一下ip 直接ping本地发现可以ping得通,代表链路是连 ...