This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define int long long
struct Point{
int x, y;
int name;
};
Point rot90(Point a){
Point res;
res.y= -a.x;
res.x =a.y;
return res;
}
Point dif(Point& a, Point& b){
Point res;
res.x= b.x-a.x;
res.y = b.y-a.y;
return res;
}
int dot(Point& a, Point& b){
return a.x*b.x+ a.y*b.y;
}
void transform(Point& p, pair<Point, Point> base){
int x= dot(p, base.first);
int y= dot(p, base.second);
p.x =x;
p.y = y;
}
const int MAX_N = 1e5;
pair<Point, Point> pts[MAX_N];
Point initial[2*MAX_N];
signed main(){
int n;
cin>>n;
for(int i = 0; i<n; i++){
Point a, b;
a.name = i*2;
b.name = i*2+1;
cin>>a.x>>a.y>>b.x>>b.y;
initial[i*2] =a;
initial[i*2+1] = b;
pts[i].first= a;
pts[i].second= b;
}
pair<Point, Point> base = { rot90(dif(pts[0].first, pts[0].second)), dif(pts[0].first, pts[0].second)};
for(int i= 0; i<n; i++){
transform(pts[i].first, base);
transform(pts[i].second, base);
//cout<<pts[i].first.x<<" "<<pts[i].first.y<<" "<<pts[i].second.x<<" "<<pts[i].second.y<<endl;
if(pts[i].first.y>pts[i].second.y){
swap(pts[i].first, pts[i].second);
}
}
auto cmp =[&](pair<Point, Point>& a, pair<Point, Point>& b){
if(a.first.x!=b.first.x){
return a.first.x<b.first.x;
}
else{
return a.first.y< b.first.y;
}
};
sort(&pts[0], &pts[n], cmp);
for(int i = 0; i<n-1; i++){
Point a= initial[pts[i].second.name];
Point b= initial[pts[i+1].first.name];
cout<<a.x<<" "<<a.y<<" "<<b.x<<" "<<b.y<<endl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |