题解 | #交叉线#
交叉线
https://www.nowcoder.com/practice/54fe00d9b0e14688bd3d31ad539b929c
#include <bits/stdc++.h>
#include <sys/types.h>
using namespace std;
typedef pair<long long int, long long int> line;
#define x first
#define y second
line arr[1005];
bool cmp( line a, line b){
if( a.x != b.x) return a.x < b.x;
else return a.y <= b.y;
}
int main() {
int T;
cin >> T;
while(T--){
int pre, nex;
int n;
cin >> n;
int cnt = 0;
for( int i = 0; i < n; i++){
if( !i ){
cin >> pre;
}
else{
cin >> nex;
arr[cnt].x = pre;
arr[cnt].y = nex;
if( arr[cnt].x > arr[cnt].y ) swap( arr[cnt].x, arr[cnt].y);
cnt++;
pre = nex;
}
}
sort( arr, arr + cnt, cmp);
// for( int i = 0; i < n-1; i++){
// cout << arr[i].x << ' ' <<arr[i].y <<endl;
// }
bool flag = false;
for(int i = 0; i < n-1; i++){
for( int j = i + 1; j < n-1; j++){
if( arr[i].x < arr[j].x && arr[i].y < arr[j].y && arr[i].y > arr[j].x){
cout << 'y' << endl;
// cout << arr[i].x << ' ' << arr[i].y <<endl;
// cout << arr[j].x <<' ' <<arr[j].y <<endl;
flag = true;
break;
}
}
if( flag ) break;
}
if(!flag)
cout << 'n' << endl;
}
return 0;
}
// 64 位输出请用 printf("%lld")
海康威视公司福利 1125人发布