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>
#define int long long
#define f first
#define s second
using namespace std;
using pii=pair<int,int>;
const int inf=1e18;
void subtask2(int n, vector<pair<pair<int,int>, pair<int,int> > >& p, vector<pair<pair<int,int>, pair<int,int> > >& old){
auto compare=[&](int i, int j){
auto a=p[i];
auto b=p[j];
if(a.first<b.first) return true;
else if(a.first>b.first) return false;
else{
if(a.second<b.second) return true;
return false;
}
};
vector<int> sorted(n);
iota(sorted.begin(), sorted.end(), 0);
sort(sorted.begin(), sorted.end(), compare);
pair<int,int> last={-inf, -inf};
for(int i=0; i<n; i++){
auto a=old[sorted[i]].first;
auto b=old[sorted[i]].second;
if(last.first!=-inf){
cout << last.first << " " << last.second << " " << a.first << " " << a.second << "\n";
}
last=b;
}
}
struct point{
int x;
int y;
point(int x=0, int y=0): x(x), y(y){};
};
struct frac{
int n;
int d;
frac(int n=1, int d=1): n(n), d(d){};
frac operator+(const frac& a)const{
int lcm=a.d*d/__gcd(a.d, d);
return frac(n*lcm/d+a.n*lcm/a.d, lcm);
}
frac operator*(const frac& a) const{
return frac(n*a.n, d*a.d);
}
bool operator<(const frac& a) const{
return n*a.d<d*a.n;
}
};
struct seg{
point p1;
point p2;
pii st;
frac li;
seg(){
p1={0, 0};
p2={0, 0};
st={1, 1};
li={1, 1};
}
seg(point point1, point point2){
p1=point1;
p2=point2;
int dx=p2.x-p1.x;
int dy=p2.y-p1.y;
st={p1.y*dx-p1.x*dy, dx};
frac m(-dx, dy);
li=frac(p1.y,1)+m*frac(p1.x, 1);
};
bool operator<(const seg& a) const{
if(li<a.li) return true;
else if(!(a.li<li)){
return p1.x<a.p1.x;
}
return false;
}
};
bool specialsorting(seg a, seg b){
if(a.st.first*b.st.second<a.st.second*b.st.first){
return true;
}
else if(a.st.first*b.st.second==a.st.second*b.st.first){
return a.p1.x<b.p1.x;
}
return false;
}
void subtask3(int n, vector<pair<pii, pii> >& p){
// sortierpunkte finden
vector<seg> s(n);
for(int i=0; i<n; i++){
s[i]=seg(point(p[i].f.f, p[i].f.s), point(p[i].s.f, p[i].s.s));
}
//sortieren
sort(s.begin(), s.end(), specialsorting);
// verbinden
for(int i=1; i<n; i++){
cout << s[i-1].p2.x << " " << s[i-1].p2.y << " " << s[i].p1.x << " " << s[i].p1.y << "\n";
}
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<pair<pair<int,int>, pair<int,int> > >p(n);
bool s2=true;
for(int i=0; i<n; i++){
cin >> p[i].first.first >> p[i].first.second;
cin >> p[i].second.first >> p[i].second.second;
if(p[i].first>p[i].second){
swap(p[i].first, p[i].second);
}
if(p[i].first.first!=p[i].second.first) s2=false;
}
if(s2){
subtask2(n, p, p);
return 0;
}
subtask3(n, p);
}
# | 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... |