FOJ Problem 2273 Triangles
Accept: 201 Submit: 661
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
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
intersect
Source
第八届福建省大学生程序设计竞赛-重现赛(感谢承办方厦门理工学院)
#define _CRT_SECURE_NO_DEPRECATE
#include <iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<bitset>
#include<set>
#include<map>
#include<cmath>
#include<queue>
using namespace std;
#define N_MAX 10000+4
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define EPS 1e-8
typedef long long ll;
struct point {
double x, y;
point(double x = , double y = ) :x(x), y(y) {}
point operator + (point p) { return point(x + p.x, y + p.y); }
point operator - (point p) { return point(x - p.x, y - p.y); }
point operator * (double a) { return point(a*x, a*y); }
double norm() { return x*x + y*y; }
bool operator < (const point &p) const{
return x != p.x ? x + EPS < p.x : y + EPS < p.y;
}
}; double dot(point a,point b) {
return a.x*b.x + a.y*b.y;
}
double det(point a,point b) {
return a.x*b.y - a.y*b.x;
}
typedef vector<point>polygon;
int contain( polygon g, point p) {//1代表在多边形内,0代表在多边形外,2在边上
int n = g.size(); bool x = ;
for (int i = ; i < n;i++) {
point a = g[i] - p, b = g[(i + ) % n] - p;
if (fabs(det(a, b)) < EPS&&dot(a, b) < EPS)return ;
if (a.y > b.y)swap(a, b);
if (a.y<EPS&&b.y>EPS&&det(a, b) > EPS)x = !x;
}
return x ? : ;
}
int ccw(point a,point b,point c) {//顺时针转还是逆时针转
point x = b - a, y = c - a;
if(det(x, y)>EPS)return ;
if (det(x, y) < -EPS)return -;
if (dot(a, b) < -EPS)return ;
if (a.norm() < b.norm())return -;
return ;
} int main() {
int t; scanf("%d",&t);
while (t--) {
polygon T1, T2;
T1.resize(); T2.resize();
for (int i = ; i < ; i++)
scanf("%lf%lf",&T1[i].x,&T1[i].y);
for (int i = ; i < ; i++)
scanf("%lf%lf", &T2[i].x, &T2[i].y);
bool is_wai = , is_nei = ,flag=;
for (int i = ; i < ;i++) {
int c = contain(T1, T2[i]);
if (c==) {
is_nei = ;
}
else if(c==)is_wai = ;
else { flag = ; break; }//在边上一定相交
}
if (flag||(is_wai&&is_nei)) { puts("intersect"); continue; }
if (is_nei && !is_wai) { puts("contain"); }
else {
is_nei = ,is_wai=;
for (int i = ; i < ;i++) {
int c = contain(T2,T1[i]);
if (c == )is_nei = ;
if (c == )is_wai = ;
}
if (is_nei&&!is_wai)puts("contain");
if (is_nei&&is_wai)puts("intersect");
else {//六个点都在另外三角形的外部,判断是否有边相交的情况
bool is_intersect = ;
point a = T1[], b = T1[];
for (int i = ; i < ; i++) {
point c = T2[i], d = T2[(i + ) % ];
if (ccw(a, b, c)*ccw(a, b, d) <= && ccw(c, d, a)*ccw(c, d, b) <= ){
is_intersect = ; break;
}
}
if (is_intersect)puts("intersect");
else puts("disjoint");
}
}
}
return ;
}
FOJ Problem 2273 Triangles的更多相关文章
- FZU 2273 Triangles 第八届福建省赛 (三角形面积交 有重边算相交)
Problem Description This is a simple problem. Given two triangles A and B, you should determine they ...
- FOJ ——Problem 1759 Super A^B mod C
Problem 1759 Super A^B mod C Accept: 1368 Submit: 4639Time Limit: 1000 mSec Memory Limit : 32 ...
- FOJ Problem 1016 无归之室
Problem 1016 无归之室 Accept: 926 Submit: 7502Time Limit: 1000 mSec Memory Limit : 32768 KB Prob ...
- FOJ Problem 1015 土地划分
Problem 1015 土地划分 Accept: 823 Submit: 1956Time Limit: 1000 mSec Memory Limit : 32768 KB Probl ...
- foj Problem 2107 Hua Rong Dao
Problem 2107 Hua Rong Dao Accept: 503 Submit: 1054Time Limit: 1000 mSec Memory Limit : 32768 K ...
- foj Problem 2282 Wand
Problem 2282 Wand Accept: 432 Submit: 1537Time Limit: 1000 mSec Memory Limit : 262144 KB Prob ...
- foj Problem 2275 Game
Problem D Game Accept: 145 Submit: 844Time Limit: 1000 mSec Memory Limit : 262144 KB Problem D ...
- foj Problem 2283 Tic-Tac-Toe
Prob ...
- FOJ Problem 2257 Saya的小熊饼干
...
随机推荐
- ES6学习(一):数值的扩展
chapter06 数值的扩展 6.1 二进制和八进制 二进制 前缀 0b 或者 0B 八进制 前缀 0o 或者 0O 6.2 Number.isFinite() Number.isNaN() 原先这 ...
- EasyUI取消树节点选中
$('#organTree').find('.tree-node-selected').removeClass('tree-node-selected'); 取消树的节点选中
- 使用Maven开发一个简单的SpringData
1:创建Maven项目 2:添加依赖(修改pom.xml为以下代码) <project xmlns="http://maven.apache.org/POM/4.0.0" x ...
- 三十五、MySQL 运算符
MySQL 运算符 本章节我们主要介绍 MySQL 的运算符及运算符的优先级. MySQL 主要有以下几种运算符: 算术运算符 比较运算符 逻辑运算符 位运算符 算术运算符 MySQL 支持的算术运算 ...
- Python_day01_作业笔记
内容大纲: 1. python的出生与应用以及历史, python2x: 源码冗余,源码重复,源码不规范. python3x: 源码清晰优美简单. 2. python的种类. Cpython: 官 ...
- 时间转换,django的时间设置,re模块简单校验密码和手机号
时间转换和密码,手机的re模块简单校验 import re,time def check_userinfo(request): pwd = request.POST.get("pwd&quo ...
- Essential C++ 3.1 节的代码练习——哨兵方式
#include "IncrementArray.hpp" template <typename element> element *find_address(elem ...
- 三次样条插值matlab实现
三次样条插值matlab实现 %三次样条差值-matlab通用程序 - zhangxiaolu2015的专栏 - CSDN博客 https://blog.csdn.net/zhangxiaolu201 ...
- Java集合中的细节问题
1)集合不保存基本数据类型,而是会把基本数据类型装箱后保存. 2)Empty和null的区别:null是不存在,Empty已经初始化了,只不过里面是空的. 3)判断集合有效性: 先判断空,再判断emp ...
- 【Python Selenium】简单数据生成脚本
最近因工作需要,写了一个简单的自动化脚本,纯属学习,顺便学习下selenium模块. 废话不多说,直接上代码!! 这里一位大神重写了元素定位.send_keys等方法,咱们直接进行调用. 适用Pyth ...