湖南大学ACM程序设计新生杯大赛(C-Do you like banana?)
2018-01-13 13:58
330 查看
时间限制: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".
示例1
有问题欢迎私聊和评论~么么哒~(难的不会写 哈哈 只有简单的)
空间限制: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<stdio.h> #include<math.h> 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 (x4<x1 || x3>x2) { 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; }
有问题欢迎私聊和评论~么么哒~(难的不会写 哈哈 只有简单的)
相关文章推荐
- 湖南大学ACM程序设计新生杯大赛(同步赛)C-Do you like Banana ? 【几何】
- 湖南大学ACM程序设计新生杯大赛(同步赛)C - Do you like Banana ?
- 湖南大学ACM程序设计新生杯大赛(同步赛)A-Array 【证明+暴力】
- 湖南大学ACM程序设计新生杯大赛(同步赛)E - Permutation
- 湖南大学ACM程序设计新生杯大赛 - Yuanyuan Long and His Ballons(环形染色问题)
- Nobody Loves Me Like You Do!
- 湖南大学ACM程序设计新生杯大赛(同步赛)I - Piglet treasure hunt Series 1
- 湖南大学ACM程序设计新生杯大赛(同步赛) D -Number 【打表+暴力】
- 湖南大学ACM程序设计新生杯大赛(同步赛)B - Build
- 湖南大学ACM程序设计新生杯大赛(同步赛)E-Permutation【打表+规律】
- 湖南大学ACM程序设计新生杯大赛(同步赛)L - Liao Han
- What to Do When You Have to Work with Someone You Don't Like
- 湖南大学ACM程序设计新生杯大赛(同步赛)G-The heap of socks【排序】
- 湖南大学ACM程序设计新生杯大赛(同步赛)A - Array
- G友年度调查|Do you like me?
- 湖南大学ACM程序设计新生杯大赛(同步赛)H-Yuanyuan Long and His Ballons【公式】
- 湖南大学ACM程序设计新生杯大赛(同步赛)J - Piglet treasure hunt Series 2
- DO YOU LIKE MY DESKTOP?
- 湖南大学ACM程序设计新生杯大赛(同步赛)H-Yuanyuan Long and His Ballons【公式】
- 2017湖南大学ACM程序设计新生杯大赛 - B - Build (并查集&&贪心)