Segments · znzryb
## 思路讲解
样例一就是选一条垂线就行。

通过样例一不难发现,只要存在一条线与所有的线段相交,那么,就可以了。
因为所有与这条线段相交的点都会投影到这条线的垂线上。
## AC代码
[https://vjudge.net/solution/63255893](https://vjudge.net/solution/63255893)
::: 源代码
```cpp
// by Gospel_rock
#include <bits/stdc++.h>
#include <cstdlib>
#include <utility>
#include <vector>
#define all(vec) vec.begin(),vec.end()
#define PB push_back
#define EB emplace_back
#define EM emplace
#define pct __builtin_popcountll
#define ctz __builtin_ctzll
#define SZ(a) ((long long) a.size())
#define debug(var) cerr << #var <<":"<<var<<"\n";
#define FI first
#define SE second
#define cend cerr<<"\n-----------\n"
#define fsp(x) fixed<<setprecision(x)
#define minn(vec) *min_element(vec.begin(),vec.end())
#define maxx(vec) *max_element(vec.begin(),vec.end())
using namespace std;
#ifdef LOCAL
template<typename T> void _print(T x) { cerr << x; }
// 可以打印多层数组,但是格式不是很好
template<typename T> void _print(vector<T> v) { cerr << "[ "; for (T i : v) _print(i), cerr << " "; cerr << "]"; }
template<typename T> void _print(set<T> s) { cerr << "{ "; for (T i : s) _print(i), cerr << " "; cerr << "}"; }
template<typename T, typename U> void _print(pair<T, U> p) { cerr << "{"; _print(p.first); cerr << ", "; _print(p.second); cerr << "}"; }
template<typename T, typename U> void _print(map<T, U> m) { cerr << "{ "; for (auto &p : m) _print(p), cerr << " "; cerr << "}"; }
// 打印两层数组,格式好一些
template<typename T> void _print(vector<vector<T>> v){cerr<<"{\n";for (auto i : v) _print(i), cerr << "\n";cerr<<" }";}
#endif
using ll = long long;using ull = unsigned long long;
using ld=double;using LD=long double;
using i128 = __int128;
using pdd = pair<ld,ld>;using plb = pair<ll,bool>;
using pll = pair<ll,ll>;using vll=vector<ll>;using vb=vector<bool>;
using tll = tuple<ll,ll,ll>;using vii=vector<int>;
using vpll = vector<pll>;using vtll = vector<tll>;
using vdb = vector<ld>;using vc=vector<char>;
using arr3 = array<ll,3> ;using arr2 = array<ll,2>;
using CD=complex<double>;
static constexpr ll MAXN=(ll)1e6+10,INF=(ll)1e17+3; // 1e17+3是素数 1e18+9是素数
static constexpr ll mod=(ll)1e9+7; // 998244353;
static constexpr double eps=1e-8;const double pi=acos(-1.0);
ll N,M,Q,X,K,T,lT;
inline void __();
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
cin>>lT;
while(lT--)
__();
return 0;
}
/*
*/
using Real = ld;
using Point = complex<Real>;
Real cross(const Point &a, const Point &b) {
return (conj(a) * b).imag();
}
Real dot(const Point &a, const Point &b) {
return (conj(a) * b).real();
}
int sgn(Real x) {
if (-eps < x && x < eps) return 0;
return x < 0 ? -1 : 1;
}
// int dcmp(double x, double y){ //比较两个浮点数:0 相等;-1 小于;1 大于
// if(fabs(x - y) < eps) return 0;
// else return x<y ?-1:1;
// }
inline void __(){
cin>>N;
vector<pair<Point, Point> > A;
vector<Point> ls;
for(int i=1;i<=N;++i){
ld a,b,c,d;
cin>>a>>b>>c>>d;
Point x(a,b),y(c,d);
A.emplace_back(x,y);
// #ifdef LOCAL
// debug(x);debug(y);
// #endif
ls.EB(x);ls.EB(y);
}
for(int i=0;i<SZ(ls);++i){
for(int j=i+1;j<SZ(ls);++j){
bool ok=true;
Point a=ls[i],b=ls[j];
// 不能是同一点
if(!sgn(a.real()-b.real()) && !sgn(a.imag()-b.imag())) continue;
for(int k=0;k<N;++k){
Point x=A[k].FI,y=A[k].SE;
if(sgn(cross(a-x,b-x))*sgn(cross(a-y,b-y))>0){
ok=false;
break;
}
}
if(ok){
cout<<"Yes!\n";
return;
}
}
}
cout<<"No!\n";
}
/*
AC
https://vjudge.net/solution/63255893
*/
// for(int i=0;i<N;++i){
// ld x=A[i].FI.real();
// Point ab=A[i].SE-A[i].FI;
// Point ab1=ab/abs(ab);
// vector<pair<ld, ld>> wp;
// for(int j=0;j<N;++j){
// ld l=dot(A[j].first-A[i].first, ab1)*ab1.real()+x;
// ld r=dot(A[j].second-A[i].first, ab1)*ab1.real();
// #ifdef LOCAL
// debug(l);debug(r);
// #endif
// wp.emplace_back(l,r);
// }
// ld l=wp[0].FI,r=wp[0].SE;
// bool ok=true;
// for(int j=1;j<N;++j){
// ld le=wp[j].FI,rr=wp[j].SE;
// if(sgn(rr-l)<0 || sgn(le-r)>0){
// ok=false;
// break;
// }
// l=max(l,le),r=min(r,rr);
// }
// if(ok){
// cout<<"Yes!\n";
// return;
// }
// }
```
:::
## 心路历程(WA,TLE,MLE……)