您的位置:首页 > 大数据 > 人工智能

【Educational Codeforces Round 41 (Rated for Div. 2) D】Pair Of Lines

2018-04-08 07:18 513 查看

【链接】 我是链接,点我呀:)
【题意】


在这里输入题意

【题解】


如果点的个数<=3
那么直接输出有解。
否则。
假设1,2最后会在一条直线上,则把这条直线上的点都删掉。
看看剩余的点是否在同一条直线上,是的话输出有解。
否则再假设1,3最后会在一条直线上,同样的看看这条直线之外的点是否 在同一条直线上。
是的话同样输出有解。
否则,因为前两种都没有解,那就说明1和2不共线,且1和3不共线,而只有两条线,且要穿过所有点。
那么就说明2,3肯定是只能在一条线上了,然后1分另外一条线。
把2,3用同样的方法判断一下就好。再不行的话,就无解了。

【代码】

#include <bits/stdc++.h>
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
using namespace std;

const double pi = acos(-1);
const int dx[4] = {0,0,1,-1};
const int dy[4] = {1,-1,0,0};
const int N = 1e5;

pair<int,int> a[N+10];
vector<pair<int,int> > v;

int n;

bool online(int x1,int y1,int x2,int y2,int x3,int y3){
LL temp1 = 1LL*(x3-x1)*(y2-y1);
LL temp2 = 1LL*(y3-y1)*(x2-x1);
if (temp1==temp2){
return true;
}else return false;
}

bool judge(int idx1,int idx2){
int x1,y1,x2,y2;
x1 = a[idx1].first,y1 = a[idx1].second,x2 = a[idx2].first,y2 = a[idx2].second;
v.clear();
for (int i = 1;i <= n;i++)
if (i!=idx1 && i!=idx2){
int x3,y3;
x3 = a[i].first,y3 = a[i].second;
if (online(x1,y1,x2,y2,x3,y3)) continue;
v.push_back(a[i]);
}
if ( (int) v.size()<=2){
return true;
}else{
x1 = v[0].first,y1 = v[0].second,x2 = v[1].first,y2 = v[1].second;
for (int i = 2;i < (int)v.size();i++){
int x3,y3;
x3 = v[i].first,y3 = v[i].second;
if (online(x1,y1,x2,y2,x3,y3)) continue;
return false;
}
return true;
}
}

int main(){
#ifdef LOCAL_DEFINE
freopen("rush_in.txt", "r", stdin);
#endif
ios::sync_with_stdio(0),cin.tie(0);
cin >> n;
rep1(i,1,n) cin >> a[i].first >> a[i].second;
if(n<=3){
cout<<"YES"<<endl;
}else{
if (judge(1,3)||judge(1,2)||judge(2,3)) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: