Pagini recente » Cod sursa (job #1262197) | Cod sursa (job #2220362) | Cod sursa (job #1874132) | Cod sursa (job #606658) | Cod sursa (job #2868141)
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define dbg(x) cout << #x <<": " << x << "\n";
using ll = long long;
class InP {
FILE *fin;
char *buff;
int sp;
public:
InP(const char *p) {
fin = fopen(p, "r");
buff = new char[4096]();
sp = 4095;
}
~InP() {
fclose(fin);
}
char read_ch() {
sp++;
if (sp == 4096) {
fread(buff, 1, 4096, fin);
sp = 0;
}
return buff[sp];
}
InP &operator >>(int &n) {
char c;
int sgn = 1;
while (!isdigit(c = read_ch()) && c != '-');
if (c == '-') {
n = 0;
sgn = -1;
}
else n = c - '0';
while (isdigit(c = read_ch()))
n = n * 10 + c - '0';
n = n * sgn;
return *this;
}
InP &operator >>(ll &n) {
char c;
int sgn = 1;
while (!isdigit(c = read_ch()) && c != '-');
if (c == '-') {
n = 0;
sgn = -1;
}
else n = c - '0';
while (isdigit(c = read_ch()))
n = n * 10LL + c - '0';
n = n * sgn;
return *this;
}
InP &operator >> (char &n) {
n = read_ch();
while ((n = read_ch()) != '\n' && n != ' ');
return *this;
}
};
class OuP {
FILE *fout;
char *buff;
int sp;
public:
OuP(const char *p) {
fout = fopen(p, "w");
buff = new char[50000];
sp = 0;
}
~OuP() {
fwrite(buff, 1, sp, fout);
fclose(fout);
}
void write_ch(char c) {
if (sp == 50000) {
fwrite(buff, 1, sp, fout);
sp = 0;
}
buff[sp++] = c;
}
OuP &operator <<(int n) {
if (n <= 9)
write_ch(n + '0');
else {
*(this) << (n / 10);
write_ch(n % 10 + '0');
}
return *this;
}
OuP &operator <<(ll n) {
if (n <= 9)
write_ch(n + '0');
else {
*(this) << (n / 10);
write_ch(n % 10 + '0');
}
return *this;
}
OuP &operator <<(char c) {
write_ch(c);
return *this;
}
OuP &operator <<(const char *c) {
while (*c) {
write_ch(*c);
c++;
}
return *this;
}
};
// InP fin("file.in");
// OuP fout("file.out");
ifstream fin("infasuratoare.in");
ofstream fout("infasuratoare.out");
typedef pair<double, double> point;
#define x first
#define y second
int n;
point a[120005];
vector<point> st;
double crossP(point a, point b, point c) {
return (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);
}
bool cmp(point p1, point p2) {
return crossP(a[1], p1, p2) < 0;
}
int main() {
fin >> n;
for (int i = 1; i <= n; ++i)
fin >> a[i].first >> a[i].second;
for (int i = 2; i <= n; ++i)
if (a[1] < a[i])
swap(a[1], a[i]);
sort(a + 2, a + n + 1, cmp);
st.pb(a[1]);
st.pb(a[2]);
for (int i = 3; i <= n; ++i) {
int top = st.size() - 1;
while (top >= 2 && crossP(st[top - 1], st[top], a[i]) > 0) {
top--;
st.pop_back();
}
st.pb(a[i]);
}
fout << st.size() << '\n';
reverse(st.begin(), st.end());
fout << fixed;
for (auto i : st)
fout << setprecision(15) << i.x << ' ' << i.y << '\n';
// fin.close();
// fout.close();
return 0;
}