题目:题目链接
这道题目就是模版题,套用凸包的计算模版就行了
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
#define maxn 55
#define pi acos(-1)
struct Point
{
int x, y;
} point[maxn];
bool operator <(const Point &a, const Point &b)
{
return atan2(a.y, a.x) < atan2(b.y, b.x);
}
double cal(double a)
{
if (a < 0)
return a + 2 * pi;
return a;
}
int main()
{
scanf("%d%d", &point[0].x, &point[0].y);
int n = 0;
while (scanf("%d%d", &point[n].x, &point[n].y) != EOF)
n++;
sort(point, point + n);
double temp = 0;
point[n] = point[0];
int s;
for (int i = 0; i < n; i++)
{
double a = cal(atan2(point[i + 1].y, point[i + 1].x) - atan2(point[i].y, point[i].x));
if (a > temp)
{
temp = a;
s = (i + 1) % n;
}
}
printf("(0,0)\n");
for (int i = 0; i < n; i++)
printf("(%d,%d)\n", point[(s + i) % n].x, point[(s + i) % n].y);
return 0;
}