【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; }
相关文章推荐
- codeforces Educational Codeforces Round 41 (Rated for Div. 2) for B problem
- Educational Codeforces Round 41 (Rated for Div. 2)
- Educational Codeforces Round 36 (Rated for Div. 2) F. Imbalance Value of a Tree(并查集)
- Educational Codeforces Round 33 (Rated for Div. 2) A - Chess For Three
- Educational Codeforces Round 36 (Rated for Div. 2) 题解
- Educational Codeforces Round 35 (Rated for Div. 2) E Stack Sorting
- Educational Codeforces Round 36 (Rated for Div. 2) E. Physical Education Lessons
- Educational Codeforces Round 37 (Rated for Div. 2) E. Connected Components?(连通分量的个数,STL)
- Educational Codeforces Round 35 (Rated for Div. 2) A——C
- Educational Codeforces Round 33 (Rated for Div. 2) B - Beautiful Divisors
- Educational Codeforces Round 38 (Rated for Div. 2) 【B】 【双指针】
- Educational Codeforces Round 34 (Rated for Div. 2)B. The Modcrab(贪心)
- Educational Codeforces Round 39 (Rated for Div. 2) codeforces946 A.Partition B.Weird Subtraction Process C.String Transformation
- Educational Codeforces Round 39 (Rated for Div. 2) A. Partition(水题)
- Educational Codeforces Round 39 (Rated for Div. 2) C. String Transformation
- Educational Codeforces Round 34 (Rated for Div. 2) C - Boxes Packing
- Educational Codeforces Round 37 (Rated for Div. 2)(A、B、C)
- Educational Codeforces Round 40 (Rated for Div. 2)
- Educational Codeforces Round 40 (Rated for Div. 2) E. Water Taps
- Educational Codeforces Round 37 (Rated for Div. 2)