【题解】CF1971C Clock and Strings
题解:CF1971C Clock and Strings
题意

在上图的一个圆中,给予你四个点 \(a,b,c,d\),判断线段 \(ab\) 与线段 \(cd\) 是否相交。
思路
先设置一个字符串 \(s\)。
从 \(1\) 到 \(12\) 扫描,如果扫描到 \(a,b\),则在 \(s\) 中加入 \(a\),如果扫到 \(c,d\),则加入 \(b\)。
经过实践足以证明,若 \(ab\) 与 \(cd\) 相交,\(s\) 必为 \(abab\) 或 \(baba\)。
Ac code
#include<bits/stdc++.h>
using namespace std;
int a,b,c,d,t;
int main() {
cin>>t;
while(t--) {
cin>>a>>b>>c>>d;
string s;
for (int i=1;i<=12;i++) {
if(i==a||i==b)s+="a";
if(i==c||i==d)s+="b";
}
if(s=="abab"||s=="baba"){
cout<<"YES\n";
}else{
cout<<"NO\n";
}
}
return 0;
}

浙公网安备 33010602011771号