Pagini recente » Cod sursa (job #1365036) | Cod sursa (job #2858163) | Cod sursa (job #2444470) | Cod sursa (job #3209205) | Cod sursa (job #1863250)
#include <bits/stdc++.h>
using namespace std;
class InParser {
private:
FILE *fin;
char *buff;
int sp;
char read_ch() {
++sp;
if (sp == 4096) {
sp = 0;
fread(buff, 1, 4096, fin);
}
return buff[sp];
}
public:
InParser(const char* nume) {
fin = fopen(nume, "r");
buff = new char[4096]();
sp = 4095;
}
InParser& operator >> (int &n) {
char c;
while (!isdigit(c = read_ch()) && c != '-');
int sgn = 1;
if (c == '-') {
n = 0;
sgn = -1;
} else {
n = c - '0';
}
while (isdigit(c = read_ch())) {
n = 10 * n + c - '0';
}
n *= sgn;
return *this;
}
InParser& operator >> (long long &n) {
char c;
n = 0;
while (!isdigit(c = read_ch()) && c != '-');
long long sgn = 1;
if (c == '-') {
n = 0;
sgn = -1;
} else {
n = c - '0';
}
while (isdigit(c = read_ch())) {
n = 10 * n + c - '0';
}
n *= sgn;
return *this;
}
} in( "oypara.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, bool ord ) {
vector<pair<int, int> > stk;
sort( pts.begin(), pts.end() );
if( ord == true )
reverse( pts.begin(), pts.end() );
for( pair<int, int> pr : pts ) {
while( stk.size() > 1 && ccw( stk[stk.size() - 2], stk[stk.size() - 1], pr ) >= 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, 0 );
lst2 = chl( lst2, 1 );
for( int pt1 = 0, pt2 = 0; pt1 + 1 < lst1.size(); pt1 ++ ) {
while( pt2 + 1 < lst2.size() && ccw( lst1[pt1], lst2[pt2], lst2[pt2 + 1] ) < 0 )
pt2 ++;
if( ccw( lst1[pt1], lst1[pt1 + 1], lst2[pt2] ) >= 0 ) {
out << lst1[pt1].first << " " << lst1[pt1].second << " ";
out << lst2[pt2].first << " " << lst2[pt2].second << endl;
return 0;
}
}
return 0;
}