Cod sursa(job #1863219)

Utilizator StarGold2Emanuel Nrx StarGold2 Data 30 ianuarie 2017 19:54:43
Problema Oypara Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.65 kb
#include <bits/stdc++.h>
using namespace std;

fstream in ( "oypara.in" , ios::in  );
fstream out( "oypara.out", ios::out );

vector<pair<int, int>> lst1, lst2;

long long ccw( pair<int, int> pt1, pair<int, int> pt2, pair<int, int> pt3 ) {
    return ( pt2.first - pt1.first ) * 1LL * ( pt3.second - pt1.second ) -
           ( pt3.first - pt1.first ) * 1LL * ( pt2.second - pt1.second );
}

vector<pair<int, int> > chl( vector<pair<int, int> > pts, int sgn ) {
    vector<pair<int, int> > stk;
    sort( pts.begin(), pts.end() );
    
    for( pair<int, int> pr : pts ) {
        while( stk.size() > 1 && ccw( stk[stk.size() - 2], stk[stk.size() - 1], pr ) * sgn <= 0 )
            stk.pop_back();
        stk.push_back( pr );
    }
    
    return stk;
}

int main( void ) {
    ios::sync_with_stdio( false );
    
    int n;
    in >> n;
    
    for( int i = 0; i < n; i ++ ) {
        int x, y1, y2;
        in >> x >> y1 >> y2;
        
        lst1.push_back( make_pair( x, y1 ) );
        lst2.push_back( make_pair( x, y2 ) );
    }
    
    lst1 = chl( lst1, +1 );
    lst2 = chl( lst2, -1 );
    
    for( int pt1 = 0, pt2 = 0; pt1 < lst1.size(); pt1 ++ ) {
        while( pt2 + 1 < lst2.size() && ccw( lst1[pt1], lst2[pt2]    , lst2[pt2 + 1] ) < 0 &&
                                        ccw( lst1[pt1], lst2[pt2 + 1], lst1[pt1 + 1] ) < 0 )
            pt2 ++;
        
        if( pt2 + 1 == lst2.size() || ccw( lst1[pt1], lst2[pt2], lst2[pt2 + 1] ) > 0 ) {
            out << lst1[pt1].first << " " << lst1[pt1].second << " ";
            out << lst2[pt2].first << " " << lst2[pt2].second << endl;
            
            return 0;
        }
    }
    
    return 0;
}