Pagini recente » Cod sursa (job #1199279) | Cod sursa (job #1317864) | Cod sursa (job #1118730) | Cod sursa (job #32159) | Cod sursa (job #1580985)
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <utility>
using namespace std;
#define maxn 122000
struct point {
double x, y;
};
int n;
vector<point> pv, sol;
point o;
long double det(point p, point q, point r)
{
return (long double)q.x*r.y + (long double)r.x*p.y + (long double)p.x*q.y - (long double)q.y*r.x - (long double)r.y*p.x - (long double) p.y*q.x;
}
long double pow(double v) {
return (long double) v*v;
}
long double dist(point a)
{
return pow(a.x-o.x) + pow(a.y-o.y);
}
bool cmp(point a, point b)
{
return ((double)(a.y-o.y)*(b.x-o.x)<=(double)(a.x-o.x)*(b.y-o.y));
}
bool Compare(point a, point b) {
return det(o, a, b) > 0 || (det(o, a, b) == 0 && dist(a) < dist(b));
}
bool compMax(point a, point b) {
if (a.x == b.x)
return a.y > b.y;
return a.x > b.x;
}
int main()
{
ifstream f("infasuratoare.in");
ofstream g("infasuratoare.out");
f>>n;
double x, y, sx = 0, sy = 0;
point p;
f>>x>>y;
o.x = x;o.y = y;
p.x = x;
p.y = y;
int index = 0;
pv.push_back(p);
for (int i = 1; i < n; i++)
{
f>>x>>y;
if (x < o.x) { index = i; o.x = x;o.y = y;}
if (x == o.x && y < o.y) { index = i; o.x = x;o.y = y;}
p.x = x;
p.y = y;
pv.push_back(p);
}
swap(pv[index],pv[0]);
sort(pv.begin()+1, pv.end(), cmp);
//rotate(pv.begin(), righty, pv.end());
sol.push_back(pv[0]);
sol.push_back(pv[1]);
for (int i = 2; i < n; i++)
{
while (sol.size() >=2 && det(sol[sol.size()-2], sol[sol.size()-1], pv[i]) < 0)
sol.pop_back();
sol.push_back(pv[i]);
}
g<<sol.size()<<'\n';
for (int i = 0; i < sol.size(); i++)
{
g<<setprecision(12) << sol[i].x<<' '<<sol[i].y<<'\n';
}
}