# 几何 直线与线段相交

#include <iostream>
#include <cstdio>
#include <cmath>
#define INF 0x3f3f3f3f
#define full(a, b) memset(a, b, sizeof a)
using namespace std;
typedef long long ll;
inline int lowbit(int x){ return x & (-x); }
int X = 0, w = 0; char ch = 0;
while(!isdigit(ch)) { w |= ch == '-'; ch = getchar(); }
while(isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();
return w ? -X : X;
}
inline int gcd(int a, int b){ return a % b ? gcd(b, a % b) : b; }
inline int lcm(int a, int b){ return a / gcd(a, b) * b; }
template<typename T>
inline T max(T x, T y, T z){ return max(max(x, y), z); }
template<typename T>
inline T min(T x, T y, T z){ return min(min(x, y), z); }
template<typename A, typename B, typename C>
inline A fpow(A x, B p, C lyd){
A ans = 1;
for(; p; p >>= 1, x = 1LL * x * x % lyd)if(p & 1)ans = 1LL * x * ans % lyd;
return ans;
}

const int N = 105;
const double eps = 1e-8;
struct Point { double x,  y;} s[N], e[N];
int n, _;

double mul(const Point &a, const Point &b, const Point &c){
return (a.x - c.x) * (b.y - c.y) - (a.y - c.y) * (b.x - c.x);
}

bool check(const Point &a, const Point &b){
if(fabs(a.x - b.x) < eps && fabs(a.y - b.y) < eps) return false;
for(int i = 0; i < n; i ++){
if(mul(a, b, s[i]) * mul(a, b, e[i]) > eps)
return false;
}
return true;
}

int main(){

while(scanf("%d", &_) != EOF){
for(; _; _ --){
scanf("%d", &n);
for(int i = 0; i < n; i ++){
scanf("%lf%lf%lf%lf", &s[i].x, &s[i].y, &e[i].x, &e[i].y);
}
if(n == 1){
printf("Yes!\n");
continue;
}
bool flag = false;
for(int i = 0; i < n; i ++){
for(int j = i + 1; j < n; j ++){
if(check(s[i], s[j]) || check(s[i], e[j]) || check(e[i], e[j]) || check(e[i], s[j])){
flag = true;
break;
}
}
if(flag) break;
}
if(flag) printf("Yes!\n");
else printf("No!\n");
}
}
return 0;
}

• 0
点赞
• 0
收藏
• 0
评论
09-04 334
10-16 591
02-14 379
11-21 34
10-20 52
01-19 609
04-01
04-01
04-01
04-01
04-01
04-01
04-01

### “相关推荐”对你有帮助么？

• 非常没帮助
• 没帮助
• 一般
• 有帮助
• 非常有帮助

1.余额是钱包充值的虚拟货币，按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载，可以购买VIP、C币套餐、付费专栏及课程。