湖南大学ACM程序设计新生杯大赛(同步赛)C - Do you like Banana ?
题目描述
输入描述:
The first line is a number of T, indicating the number of tests inputed (1 <= T <= 1000)
For next T line,each line contains 8 numbers , x1,y1,x2,y2,x3,y3,x4, y4. (8-10 ^ < = xi, yi < = 10 ^ 8)
(the two endpoints of line 1 are x1, y1, |, x2, y2, and two of the endpoints of line 2 are x3, y3, |, x4, y4).
输出描述:
For each test case, output"Yes" if the two segments intersected, else output"No".
输入
2
1 2 2 1 0 0 2 2
-1 1 1 1 0 0 1 -1
输出
Yes
No
题解
判断线段非严格相交。
#include<cstdio>
using namespace std; const double eps=1e-8;
#define zero(x)(((x)>0?(x):(-x))<eps) struct point
{
double x, y;
}; 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 dots_inline(point p1,point p2,point p3)
{
return zero(xmult(p1,p2,p3));
} int same_side(point p1,point p2,point l1,point l2)
{
return xmult(l1,p1,l2)*xmult(l1,p2,l2)>eps;
} 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 intersect_in(point u1,point u2,point v1,point v2)
{
if(!dots_inline(u1,u2,v1)||!dots_inline(u1,u2,v2)) return !same_side(u1,u2,v1,v2)&&!same_side(v1,v2,u1,u2);
return dot_online_in(u1,v1,v2)||dot_online_in(u2,v1,v2)||dot_online_in(v1,u1,u2)||dot_online_in(v2,u1,u2);
} //调用intersect_in,相交返回1 int main() {
int T;
scanf("%d", &T);
while(T --) {
point a, b, c, d;
scanf("%lf%lf%lf%lf", &a.x, &a.y, &b.x, &b.y);
scanf("%lf%lf%lf%lf", &c.x, &c.y, &d.x, &d.y);
if(intersect_in(a,b,c,d)) printf("Yes\n");
else printf("No\n");
}
return 0;
}
湖南大学ACM程序设计新生杯大赛(同步赛)C - Do you like Banana ?的更多相关文章
- 湖南大学ACM程序设计新生杯大赛(同步赛)J - Piglet treasure hunt Series 2
题目描述 Once there was a pig, which was very fond of treasure hunting. One day, when it woke up, it fou ...
- 湖南大学ACM程序设计新生杯大赛(同步赛)A - Array
题目描述 Given an array A with length n a[1],a[2],...,a[n] where a[i] (1<=i<=n) is positive integ ...
- 湖南大学ACM程序设计新生杯大赛(同步赛)L - Liao Han
题目描述 Small koala special love LiaoHan (of course is very handsome boys), one day she saw N (N<1e1 ...
- 湖南大学ACM程序设计新生杯大赛(同步赛)B - Build
题目描述 In country A, some roads are to be built to connect the cities.However, due to limited funds, ...
- 湖南大学ACM程序设计新生杯大赛(同步赛)I - Piglet treasure hunt Series 1
题目描述 Once there was a pig, which was very fond of treasure hunting. The treasure hunt is risky, and ...
- 湖南大学ACM程序设计新生杯大赛(同步赛)E - Permutation
题目描述 A mod-dot product between two arrays with length n produce a new array with length n. If array ...
- 湖南大学ACM程序设计新生杯大赛(同步赛)D - Number
题目描述 We define Shuaishuai-Number as a number which is the sum of a prime square(平方), prime cube(立方), ...
- 湖南大学ACM程序设计新生杯大赛(同步赛)H - Yuanyuan Long and His Ballons
题目描述 Yuanyuan Long is a dragon like this picture? I don’t know, ...
- 湖南大学ACM程序设计新生杯大赛(同步赛)G - The heap of socks
题目描述 BSD is a lazy boy. He doesn't want to wash his socks, but he will have a data structure called ...
随机推荐
- ZOJ 3778 C - Talented Chef 水题
LINK:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3778 题意:有n道菜,每道菜需要\(a_i\)道工序,有m个锅可 ...
- c# WebService SOAP及Rest调用
SOAP及Rest的调用区别参照如下: REST似乎在一夜间兴起了,这可能引起一些争议,反对者可以说REST是WEB诞生之始甚而是HTTP出现之日就相伴而生的原则.但是毋庸置疑的事实是,在Google ...
- Elasticsearch——QueryBuilder简单查询
elasticsearch中存储的全部文档 1.matchAllQuery() matchAllQuery()方法用来匹配全部文档 public class QueryTest { pub ...
- 您是哪个等级的CSS开发人员?
我们在不断的学习,追求进步与提高,到底学到什么程度了,到底是 不是真的了解CSS,是哪个层次了呢.我们来对照一下. 第0级:CSS?那不是一个多人射击游戏吗? CSS? Isn't that a m ...
- [linux]codeblocks开发mysql配置
1.在安装好mysql后,可以应该安装必要的库文件 $sudo apt-get install libmysqlclient-dev 2.将codeblocks与mysql的库文件连接起来 在code ...
- [转]C语言指针详解(经典,非常详细)
博文地址:https://blog.csdn.net/constantin_/article/details/79575638 写得很好啊! 这里写一下笔记好了 int p; //这是一个普通的整型变 ...
- 【BZOJ】2599: [IOI2011]Race 点分治
[题意]给一棵树,每条边有权.求一条简单路径,权值和等于K,且边的数量最小.N <= 200000, K <= 1000000.注意点从0开始编号,无解输出-1. [算法]点分治 [题解] ...
- ajax做显示信息以后用ajax、Bootstrp做弹窗显示信息详情
1.用ajax做弹窗显示信息详情 nation.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN&qu ...
- iOS网络基础---iOS-Apple苹果官方文档翻译
CHENYILONG Blog iOS网络基础---iOS-Apple苹果官方文档翻译 iOS网络基础 技术博客http://www.cnblogs.com/ChenYilong/ 新浪微博http: ...
- 关于HttpWebRequest发生服务器协议冲突的解决办法
WinForm下的app.config文件中添加: <system.net> <settings> <httpWebRequest useUnsafeHe ...