凸包模板题目。
/* 3285 */
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std; #define MAXN 55 typedef struct {
int x, y;
} Point_t; Point_t points[MAXN];
Point_t stack[MAXN];
int top; void output(int); double dist(Point_t a, Point_t b) {
return sqrt(1.0*(a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y));
} int dist2(Point_t a, Point_t b) {
return (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y);
} int cross(Point_t a, Point_t b, Point_t c) {
return (b.x-a.x)*(c.y-a.y) - (c.x-a.x)*(b.y-a.y);
} bool comp(Point_t a, Point_t b) {
int m = cross(points[], a, b);
return m> || (m== && dist2(points[], a)<dist2(points[], b));
} void Graham(int n) {
Point_t p;
int i, j, k; p = points[];
k = ;
for (i=; i<n; ++i) {
if (points[i].x<p.x || (points[i].x==p.x && points[i].y<p.y)) {
p = points[i];
k = i;
}
}
points[k] = points[];
points[] = p; sort(points+, points+n, comp); stack[] = points[];
stack[] = points[];
top = ; for (i=; i<n; ++i) {
while(top && cross(stack[top-], stack[top], points[i])<=)
--top;
stack[++top] = points[i];
}
} int main() {
int t, case_n;
int n;
int i, j, k;
Point_t p; #ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
#endif scanf("%d", &t);
while (t--) {
scanf("%d %d", &case_n, &n);
for (i=; i<n; ++i)
scanf("%d %d", &points[i].x, &points[i].y);
Graham(n);
printf("%d %d\n", case_n, top+);
p = stack[];
k = ;
for (i=; i<=top; ++i) {
if (stack[i].y>p.y || (stack[i].y==p.y && stack[i].x<p.x)) {
p = stack[i];
k = i;
}
}
for (i=k; i>=; --i)
printf("%d %d\n", stack[i].x, stack[i].y);
for (i=top; i>k; --i)
printf("%d %d\n", stack[i].x, stack[i].y);
} return ;
}