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
 
观察样例可以发现,如果边有重叠部分,此题也算相交。
因此我套用多边形面积交的模板http://www.cnblogs.com/Annetree/p/6535294.html
如果有重合面积,有两种情况:包含或相交,特殊判断包含即可
如果没有重合面积,也有两种情况:相交(线)和相离,特殊判断线部分重合即可
 
 #include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<queue>
#include<map>
#include<stack>
#include<set> using namespace std; const int maxn=;
const int maxisn=;
const double eps=1e-;
const double pi=acos(-1.0); int dcmp(double x){
if(x>eps) return ;
return x<-eps ? - : ;
}
inline double Sqr(double x){
return x*x;
} #define zero(x)(((x)>0?(x):-(x))<eps)
struct Point{
double x,y;
Point(){x=y=;}
Point(double x,double y):x(x),y(y){};
friend Point operator + (const Point &a,const Point &b) {
return Point(a.x+b.x,a.y+b.y);
}
friend Point operator - (const Point &a,const Point &b) {
return Point(a.x-b.x,a.y-b.y);
}
friend bool operator == (const Point &a,const Point &b) {
return dcmp(a.x-b.x)==&&dcmp(a.y-b.y)==;
}
friend Point operator * (const Point &a,const double &b) {
return Point(a.x*b,a.y*b);
}
friend Point operator * (const double &a,const Point &b) {
return Point(a*b.x,a*b.y);
}
friend Point operator / (const Point &a,const double &b) {
return Point(a.x/b,a.y/b);
}
friend bool operator < (const Point &a, const Point &b) {
return a.x < b.x || (a.x == b.x && a.y < b.y);
}
inline double dot(const Point &b)const{
return x*b.x+y*b.y;
}
inline double cross(const Point &b,const Point &c)const{
return (b.x-x)*(c.y-y)-(c.x-x)*(b.y-y);
} }; Point LineCross(const Point &a,const Point &b,const Point &c,const Point &d){
double u=a.cross(b,c),v=b.cross(a,d);
return Point((c.x*v+d.x*u)/(u+v),(c.y*v+d.y*u)/(u+v));
}
double PolygonArea(Point p[],int n){
if(n<) return 0.0;
double s=p[].y*(p[n-].x-p[].x);
p[n]=p[];
for(int i=;i<n;i++){
s+=p[i].y*(p[i-].x-p[i+].x);
}
return fabs(s*0.5);
}
double CPIA(Point a[],Point b[],int na,int nb){
Point p[maxisn],temp[maxisn];
int i,j,tn,sflag,eflag;
a[na]=a[],b[nb]=b[];
memcpy(p,b,sizeof(Point)*(nb+));
for(i=;i<na&&nb>;++i){
sflag=dcmp(a[i].cross(a[i+],p[]));
for(j=tn=;j<nb;++j,sflag=eflag){
if(sflag>=) temp[tn++]=p[j];
eflag=dcmp(a[i].cross(a[i+],p[j+]));
if((sflag^eflag)==-)
temp[tn++]=LineCross(a[i],a[i+],p[j],p[j+]);
}
memcpy(p,temp,sizeof(Point)*tn);
nb=tn,p[nb]=p[];
}
if(nb<) return 0.0;
return PolygonArea(p,nb);
}
double SPIA(Point a[],Point b[],int na,int nb){
int i,j;
Point t1[],t2[];
double res=0.0,if_clock_t1,if_clock_t2;
a[na]=t1[]=a[];
b[nb]=t2[]=b[];
for(i=;i<na;i++){
t1[]=a[i-],t1[]=a[i];
if_clock_t1=dcmp(t1[].cross(t1[],t1[]));
if(if_clock_t1<) swap(t1[],t1[]);
for(j=;j<nb;j++){
t2[]=b[j-],t2[]=b[j];
if_clock_t2=dcmp(t2[].cross(t2[],t2[]));
if(if_clock_t2<) swap(t2[],t2[]);
res+=CPIA(t1,t2,,)*if_clock_t1*if_clock_t2;
}
}
return res;
//return PolygonArea(a,na)+PolygonArea(b,nb)-res;
} Point a[],b[];
Point aa[],bb[]; double length(Point p1,Point p2)//求边长
{
double res=sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));
return res;
} double area_triangle(double l1,double l2,double l3)//求三角形面积
{
double s=(l1+l2+l3)/2.0;
double res=sqrt(s*(s-l1)*(s-l2)*(s-l3));
return res;
} 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 parallel(Point u1,Point u2,Point v1,Point v2)//判断平行
{
return zero((u1.x-u2.x)*(v1.y-v2.y)-(v1.x-v2.x)*(u1.y-u2.y));
} 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;
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
for(int i=;i<;i++) scanf("%lf %lf",&a[i].x,&a[i].y);
for(int i=;i<;i++) scanf("%lf %lf",&b[i].x,&b[i].y);
double area_double =fabs(SPIA(a,b,,));//重合面积
double l1=length(a[],a[]),l2=length(a[],a[]),l3=length(a[],a[]);
double l4=length(b[],b[]),l5=length(b[],b[]),l6=length(b[],b[]);
if(area_double>eps) //包含或相交
{
if(abs(area_double-area_triangle(l1,l2,l3))<eps)
printf("contain\n");
else if(abs(area_double-area_triangle(l4,l5,l6))<eps)
printf("contain\n");
else
printf("intersect\n");
}
else //相交或相离
{
bool flag=false;
//判断是否有边重合
for(int i=;i<;i++)
{
for(int ii=i+;ii<;ii++)
{
for(int j=;j<;j++)
{
for(int jj=j+;jj<;jj++)
{
if(parallel(a[i],a[ii],b[j],b[jj]))
if(dot_online_in(a[i],b[j],b[jj]))
{
flag=true;
break;
}
}
if(flag)
break;
}
if(flag)
break;
}
if(flag)
break;
}
if(flag)
printf("intersect\n");
else
printf("disjoint\n"); }
}
return ;
}

FZU 2273 Triangles 第八届福建省赛 (三角形面积交 有重边算相交)的更多相关文章

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

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

  2. FOJ Problem 2273 Triangles

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

  3. 第八届河南省赛B.最大岛屿(dfs)

    B.最大岛屿 Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 30  Solved: 18 [Submit][Status][Web Board] De ...

  4. TZOJ 2519 Regetni(N个点求三角形面积为整数总数)

    描述 Background Hello Earthling. We're from the planet Regetni and need your help to make lots of mone ...

  5. ytu 1058: 三角形面积(带参的宏 练习)

    1058: 三角形面积 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 190  Solved: 128[Submit][Status][Web Boar ...

  6. UVa 11437:Triangle Fun(计算几何综合应用,求直线交点,向量运算,求三角形面积)

    Problem ATriangle Fun Input: Standard Input Output: Standard Output In the picture below you can see ...

  7. OpenJudge计算概论-计算三角形面积【海伦公式】

    /*============================================== 计算三角形面积 总时间限制: 1000ms 内存限制: 65536kB 描述 平面上有一个三角形,它的 ...

  8. bzoj 1845: [Cqoi2005] 三角形面积并 扫描线

    1845: [Cqoi2005] 三角形面积并 Time Limit: 3 Sec  Memory Limit: 64 MBSubmit: 848  Solved: 206[Submit][Statu ...

  9. nyoj 67 三角形面积【三角形面积公式】

    三角形面积 时间限制:3000 ms  |  内存限制:65535 KB 难度:2   描述 给你三个点,表示一个三角形的三个顶点,现你的任务是求出该三角形的面积   输入 每行是一组测试数据,有6个 ...

随机推荐

  1. 创建springboot的聚合工程(三)

    springboot聚合工程之添加mybatis数据库持久化操作 在boot-polymer-repository工程添加mybatis的相关依赖 <project xmlns="ht ...

  2. 遇到后缀名为whl的库的安装方法

    直接把whl文件改成zip文件,解压到site-packages里面,其中site-packages文件夹位于例如我的位置是e:/python34/lib/sit-packages即可,然后就可以用i ...

  3. ThinkPHP3的使用

    1. 初始目录 7d 根目录 ├─Application 应用目录(空) ├─Public 资源文件目录 ├─ThinkPHP 框架目录 └─index.php 入口文件 2. 入口文件 // 应用入 ...

  4. 深入Spring Boot: 怎样排查 java.lang.ArrayStoreException

    java.lang.ArrayStoreException 分析 这个demo来说明怎样排查一个spring boot 1应用升级到spring boot 2时可能出现的java.lang.Array ...

  5. vue-navigation 实现前进刷新,后退不刷新

    vue-navigation GitHub地址 导航默认行为类似手机APP的页面导航(A.B.C为页面): A前进到B,再前进到C: C返回到B时,B会从缓存中恢复: B再次前进到C,C会重新生成,不 ...

  6. 查验身份证 (15 分) 一个合法的身份证号码由17位地区、日期编号和顺序编号加1位校验码组成。校验码的计算规则如下: 首先对前17位数字加权求和,权重分配为:{7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2};然后将计算的和对11取模得到值Z;最后按照以下关系对应Z值与校验码M的值:

    // test4.cpp : 此文件包含 "main" 函数.程序执行将在此处开始并结束.// #include "pch.h"#include <ios ...

  7. -L、-rpath和-rpath-link的区别

    链接器ld的选项有 -L,-rpath 和 -rpath-link,看了下 man ld,大致是这个意思: -L::  “链接”的时候去找的目录,也就是所有的 -lFOO 选项里的库,都会先从 -L ...

  8. AI工具(星形工具)(光晕工具)(移动复制)(柜子绘制)5.12

    星形工具;基本操作与矩形一样,拖动星形工具绘制,点击键盘上箭头增加星形的角数.下箭头减少星形的角数. 选择星形工具在屏幕单击,出现星形对话框,可以设置半径1半径2,角点数.图中的星形就可以用星形工具绘 ...

  9. java 的类型转换方式

    隐式转换 byte等整型转int,最高位(符号位保留),中间补0 byte bt=-13; bt 源码:1000 1101 反码:1111 0010 补码:1111 0011 int it=bt; i ...

  10. 摄像头录制视频并且保存成mp4

    import cv2import numpy as npimport os cap = cv2.VideoCapture(1)#v4l2-ctl --list-devices 查看设备号,非正常中断时 ...