#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#pragma warning(disable:4996)
using namespace std;
const double eps = 1e-9;
const double pi = acos(-1.0);
int cmp(const double &x)
{
if (fabs(x) < eps)
{
return 0;
}
if (x > 0)
{
return 1;
}
return -1;
}
inline double sqr(const double &x)
{
return x*x;
}
class Point
{
public:
double x, y;
Point() {}
Point(const double &a, const double &b) :x(a), y(b) {}
void input()
{
cin >> x >> y;
}
friend Point operator+(const Point &a, const Point &b)
{
return Point(a.x+b.x,a.y+b.y);
}
friend Point operator-(const Point &a, const Point &b)
{
return Point(a.x - b.x, a.y - b.y);
}
friend bool operator==(const Point &a, const Point &b)
{
return cmp(a.x - b.x) == 0 && cmp(a.y - b.y) == 0;
}
friend Point operator*(const Point &a,const double &b)
{
return Point(a.x*b, a.y*b);
}
friend Point operator*(const double &a, const Point &b)
{
return Point(b.x*a, b.y*a);
}
friend Point operator/(const Point &a, const double &b)
{
return Point(a.x / b, a.y / b);
}
double norm()
{
return sqrt(sqr(x)+ sqr(y));
}
};
double det(const Point &a, const Point &b)
{
return a.x*b.y - a.y * b.x;
}
double dot(const Point &a, const Point &b)
{
return a.x*b.x + a.y * b.y;
}
double dist(const Point &a, const Point &b)
{
return (a - b).norm();
}
Point rotate_point(const Point&p,const double &A)
{
double tx = p.x, ty = p.y;
return Point(tx*cos(A)-ty*sin(A),tx*sin(A)+ty*cos(A));
}
class Line
{
public:
Point a, b;
Line() {}
Line(const Point&x, const Point &y) :a(x), b(y) {}
Line point_make_line(const Point &a,const Point &b)
{
return Line(a, b);
}
};
double dist_point_segment(const Point &p,const Point &s,const Point &t)
{
if (cmp(dot(p-s,t-s))<0)
{
return (p - s).norm();
}
if (cmp(dot(p -t , s - t)) < 0)
{
return (p - t).norm();
}
return fabs(det(s - p, t - p) / dist(s, t));
}
void PointProjLine(const Point &p,const Point &s,const Point&t,Point &cp)
{
double r = dot((t-s),(p-s))/dot(t-s,t-s);
cp = s + r*(t - s);
}
bool PointOnSegment(const Point&p,const Point &s,const Point &t)
{
return cmp(det(p - s, t - s)) == 0 && cmp(dot(p - s, p - t)) <= 0;
}
bool parallel(const Line&a,const Line&b)
{
return !cmp(det(a.a - a.b, b.a - b.b));
}
bool line_make_point(const Line &a, const Line&b, Point &res)
{
if (parallel(a, b)) return false;
double s1 = det(a.a - b.a, b.b - b.a);
double s2 = det(a.b - b.a, b.b - b.a);
res = (s1*a.b - s2*a.a) / (s1 - s2);
return true;
}
Line move_d(const Line &a, const double &len)
{
Point d = a.b - a.a;
d = d / d.norm();
d = rotate_point(d, pi / 2);
return Line(a.a + d*len, a.b + d*len);
}
bool comp_less(const Point &a, const Point &b)
{
return cmp(a.x - b.x) < 0 || cmp(a.x - b.x) == 0 && cmp(a.y - b.y) < 0;
}
class ConvexPolygon
{
public:
vector<Point>point;
ConvexPolygon(const int &n)
{
vector<Point>a(n);
for (int i = 0; i < n; i++)
{
cin >> a[i].x >> a[i].y;
}
point.resize(2 * a.size() + 5);
sort(a.begin(), a.end(), comp_less);
a.erase(unique(a.begin(), a.end()), a.end());
int m = 0;
for (int i = 0; i < a.size(); i++)
{
while (m > 1 && cmp(det(point[m - 1] - point[m - 2], a[i] - point[m - 2])) <= 0)
{
m--;
}
point[m++] = a[i];
}
int k = m;
for (int i = int(a.size()) - 2; i >= 0; i--)
{
while (m > k&&cmp(det(point[m - 1] - point[m - 2], a[i] - point[m - 2])) <= 0)
{
m--;
}
point[m++] = a[i];
}
point.resize(m);
if (a.size() > 1)
{
point.resize(m - 1);
}
}
double perimeter()
{
double sum = 0.0;
for (int i = 0; i < (int)point.size() - 1; i++)
{
sum += (point[i + 1] - point[i]).norm();
}
sum += (point[0] - point[point.size() - 1]).norm();
return sum;
}
double area()
{
double sum = 0.0;
for (int i = 0; i < (int)point.size() - 1; i++)
{
sum += det(point[i + 1] , point[i]);
}
sum += det(point[0] , point[point.size() - 1]);
return sum/2.0;
}
int PointInPolygon(const Point &t)
{
int num = 0, d1, d2, k,n=point.size();
point.push_back(point[0]);
for (int i = 0; i < n; i++)
{
if (PointOnSegment(t, point[i], point[i + 1]))
{
return 2;
}
k = cmp(det(point[i+1]-point[i],t-point[i]));
d1 = cmp(point[i].y - t.y);
d2 = cmp(point[i + 1].y - t.y);
if (k > 0 && d1 <= 0 && d2>0)
{
num++;
}
if (k < 0 && d2 <= 0 && d1>0)
{
num--;
}
}
point.pop_back();
return num != 0;
}
Point getMassCenter()
{
Point ans = Point(0,0);
if (cmp(area()) == 0)
{
return ans;
}
point.push_back(point[0]);
for (int i = 0; i < point.size()-1; i++)
{
ans = ans+(point[i] + point[i + 1])*det(point[i + 1], point[i]);
}
return ans / area() / 6.0;
}
void print()
{
cout << point.size()+1 << endl;
int index = 0;
for (int i = 0; i != (int)point.size(); i++)
{
if (point[index].y > point[i].y)
{
index = i;
}
}
cout << point[index].x << ' ' << point[index].y << endl;
index++;
for (int i=0;i<(int)point.size();i++,index++)
{
cout << point[index%point.size()].x << ' ' << point[index%point.size()].y << endl;
}
}
};
int main()
{
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
int T;
while (cin >> T)
{
cout << T << endl;
while (T--)
{
int n; cin >> n;
ConvexPolygon polygon(n);
polygon.print();
if (T)
{
cout << "-1" << endl;
int value; cin >> value;
}
}
}
return 0;
}
uva_681_Convex Hull Finding
最新推荐文章于 2020-11-28 23:33:44 发布