Mephistopheles_

Треугольники 2

Feb 4th, 2021
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.76 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. using ll=unsigned long long;
  4. int main(){
  5.     int x[3],y[3],r[3],o[3],n;bool b=1;vector<pair<int,pair<int,int>>>d(3),d1(3);
  6.     vector<pair<int,int>>co;
  7.     cin>>n;
  8.     cin>>x[0]>>y[0]>>x[1]>>y[1]>>x[2]>>y[2];
  9.     co.push_back({x[0],y[0]});
  10.     co.push_back({x[1],y[1]});
  11.     co.push_back({x[2],y[2]});
  12.     sort(co.begin(),co.end());
  13.     d[0].first=(co[1].first-co[0].first)*(co[1].first-co[0].first)+(co[1].second-co[0].second)*(co[1].second-co[0].second);
  14.     d[1].first=(co[2].first-co[1].first)*(co[2].first-co[1].first)+(co[2].second-co[1].second)*(co[2].second-co[1].second);
  15.     d[2].first=(co[2].first-co[0].first)*(co[2].first-co[0].first)+(co[2].second-co[0].second)*(co[2].second-co[0].second);
  16.     d[0].second={co[1].first-co[0].first,co[1].second-co[0].second};
  17.     d[1].second={co[2].first-co[1].first,co[2].second-co[1].second};
  18.     d[2].second={co[2].first-co[0].first,co[2].second-co[0].second};
  19.     sort(d.begin(),d.end());
  20.     for(int i=0;i<n-1;++i){
  21.         cin>>x[0]>>y[0]>>x[1]>>y[1]>>x[2]>>y[2];
  22.         co.clear();
  23.         co.push_back({x[0],y[0]});
  24.         co.push_back({x[1],y[1]});
  25.         co.push_back({x[2],y[2]});
  26.         sort(co.begin(),co.end());
  27.         d1[0].first=(co[1].first-co[0].first)*(co[1].first-co[0].first)+(co[1].second-co[0].second)*(co[1].second-co[0].second);
  28.         d1[1].first=(co[2].first-co[1].first)*(co[2].first-co[1].first)+(co[2].second-co[1].second)*(co[2].second-co[1].second);
  29.         d1[2].first=(co[2].first-co[0].first)*(co[2].first-co[0].first)+(co[2].second-co[0].second)*(co[2].second-co[0].second);
  30.         d1[0].second={co[1].first-co[0].first,co[1].second-co[0].second};
  31.         d1[1].second={co[2].first-co[1].first,co[2].second-co[1].second};
  32.         d1[2].second={co[2].first-co[0].first,co[2].second-co[0].second};
  33.         sort(d1.begin(),d1.end());
  34.         if((d[0].first==d[1].first || d[1].first==d[2].first) &&(d1[0].first==d1[1].first || d1[1].first==d1[2].first) && (d1[1].first==d[1].first))
  35.             continue;
  36.         r[0]=(d[0].second.first*d[1].second.second-d[0].second.second*d[1].second.first);
  37.         o[0]= (d1[0].second.first*d1[1].second.second-d1[0].second.second*d1[1].second.first);
  38.         r[1]=(d[0].second.first*d[2].second.second-d[0].second.second*d[2].second.first);
  39.         o[1]= (d1[0].second.first*d1[2].second.second-d1[0].second.second*d1[2].second.first);
  40.         r[2]=(d[1].second.first*d[2].second.second-d[1].second.second*d[2].second.first);
  41.         o[2]= (d1[1].second.first*d1[2].second.second-d1[1].second.second*d1[2].second.first);
  42.         if(r[0]*o[0]<0 ||r[1]*o[1]<0 ||r[2]*o[2]<0 || d[0].first!=d1[0].first || d[1].first!=d1[1].first || d[2].first!=d1[2].first)b=0;
  43.     }
  44.     if(b)cout<<"YES";
  45.     else cout<<"NO";
  46. }
Advertisement
Add Comment
Please, Sign In to add comment