热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

湖南大学ACM程序设计新生杯大赛(C-Doyoulikebanana?)

时间限制:CC++1秒,其他语言2秒空间限制:CC++32768K,其他语言65536K64bitIOFormat:%lld
时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 32768K,其他语言65536K
64bit IO Format: %lld

题目描述 


Two endpoints of two line segments on a plane are given to determine whether the two segments are intersected (there is a common point or there is a partial coincidence that intersects). If intersected, output "Yes", otherwise output "No".

输入描述:

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".
示例1

输入

2
1 2 2 1 0 0 2 2
-1 1 1 1 0 0 1 -1

输出

Yes
No
代码:
#include
#include
int T;
double x1, y, x2, y2, x3, y3, x4, y4;
void fun()
{
double k1, k2, b1, b2;
k1 = (y2 - y) / (x2 - x1);
k2 = (y4 - y3) / (x4 - x3);
b1 = y - k1*x1;
b2 = y3 - k2*x3;
double t;
if (x1>x2) { t = x1; x1 = x2; x2 = t; }
if (x3>x4) { t = x3; x3 = x4; x4 = t; }
if (y>y2) { t = y; y = y2; y2 = t; }
if (y3>y4) { t = y3; y3 = y4; y4 = t; }
if (k1 == k2 && b1 != b2) { printf("No\n"); return; }
else if (k1 == k2 && b1==b2)
{
if (x4x2) { printf("No\n"); return; }
else { printf("Yes\n"); return; }
}
else if (k1 != k2)
{
double x = (b2 - b1) / (k1 - k2);
if (x <= x2&&x >= x1&&x <= x4&&x >= x3) { printf("Yes\n"); return; }
else { printf("No\n"); return; }
}
}
int main()
{
scanf("%d", &T);
while (T--)
{
scanf("%lf%lf%lf%lf%lf%lf%lf%lf", &x1, &y, &x2, &y2, &x3, &y3, &x4, &y4);
fun();
}
return 0;
}

有问题欢迎私聊和评论~么么哒~(难的不会写 哈哈 只有简单的)

推荐阅读
author-avatar
呦呦嘉宾
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有