湖南大学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 ...
随机推荐
- OpenCV---图像金字塔原理
图像金字塔原理 (一)图像缩小(先高斯模糊,再降采样,需要一次次重复,不能一次到底) (二)图像扩大(先扩大,再卷积或者使用拉普拉斯金字塔) 图像金字塔介绍 图像金字塔是图像中多尺度表达的一种,最主要 ...
- css单位em、px、rem和pt的区别
1.PX :像素(Pixel) PX是相对长度单位,它是相对于显示器屏幕分辨率而言的. 优缺点:比较稳定和精确,但在浏览器中放大或缩放浏览页面时会出现页面混乱的情况. 2.EM:是相对长度单位. EM ...
- jQuery代码优化:基本事件
jQuery对事件系统的抽象与优化也是它的一大特色.本文仅从事件系统入手,简要分析一下jQuery为什么提供mouseenter和mouseleave事件,它们与标准的mouseover.mouseo ...
- DHTML中window的使用
window对象是对浏览器窗口进行操作的对象.以下列出一些常用的对象(三级为对象的方法.属性) |-navigator:是对浏览器信息进行操作的对象 |-history:包含用户浏览过的url信息 | ...
- 【Codeforces752D】Santa Claus and a Palindrome [STL]
Santa Claus and a Palindrome Time Limit: 20 Sec Memory Limit: 512 MB Description 有k个串,串长都是n,每个串有一个a ...
- js小记:对象、原型及原型链、面向对象编程
一.js对象 1.js对象 js对象是一种复合数据类型,它可以把多个(不同类型的)数据集中在一个变量中,并且给每个数据起名字. 2.对象与数组 对象的每个数据有对应的名字(属性名),我们通过叫名字访问 ...
- 51Nod 1256 扩展欧几里得求乘法逆元
给出2个数M和N(M < N),且M与N互质,找出一个数K满足0 < K < N且K * M % N = 1,如果有多个满足条件的,输出最小的. Input 输入2个数M, N中间用 ...
- python作业Select版本FTP(第十周)
SELECT版FTP: 使用SELECT或SELECTORS模块实现并发简单版FTP 允许多用户并发上传下载文件 思路解析: 1. 使用IO多路复用的知识使用SELECTORS封装好的SELECTOR ...
- 初识smarty
个人体会(不完全正确):就是smarty就是为了更好的使得php/html结合做出来的一个框架. ,
- Linux CentOS 6.9(图形界面)安装中文输入法
安装步骤 1. 切换到 root 用户,执行 yum -y install "@Chinese Support" 2. 退出终端,选择桌面菜单中 "System" ...