Pagini recente » Cod sursa (job #1702900) | Cod sursa (job #12882) | Cod sursa (job #1191252) | Cod sursa (job #2802509) | Cod sursa (job #2284428)
#include <iostream>
#include <fstream>
#include <vector>
#include <stack>
#include <algorithm>
#define pii pair <double, double>
#define x first
#define y second
using namespace std;
ifstream fin ("infasuratoare.in");
ofstream fout ("infasuratoare.out");
vector <pii> v;
int st[120010];
int n, top;
double a, b;
double det (pii a, pii b, pii c){
int ans = a.x * b.y + b.x * c.y + c.x * a.y - c.x * b.y - a.x * c.y - b.x * a.y;
return ans;
}
int main()
{
fin >> n;
v.push_back({0, 0});
for (int i=1; i<=n; i++){
fin >> a >> b;
v.push_back({a, b});
}
sort (v.begin(), v.end());
for (int i=1; i<=n; i++){
cout << v[i].x << ' ' << v[i].y << '\n';
}
st[++top] = 1;
for (int i=2; i<=n; i++){
if (top == 1)
st[++top] = i;
else{
while (top >=2 && det (v[st[top-1] ], v[ st[top] ], v[i] )> 0)
top--;
st[++top] = i;
}
}
for (int i=1; i<=top; i++)
fout << v[st[i]].x << ' ' << v[st[i]].y << '\n';
top = 0;
st[++top] = n;
for (int i=n-1; i>=1; i--){
if (top == 1)
st[++top] = i;
else{
while (top >=2 && det (v[st[top-1] ], v[ st[top] ], v[i] )> 0)
top--;
st[++top] = i;
}
}
for (int i=2; i<top; i++)
fout << v[st[i]].x << ' ' << v[st[i]].y << '\n';
return 0;
}