Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <math.h>
- #include <stdlib.h>
- #include <stack>
- #include <queue>
- #include <set>
- #include <map>
- #include <string>
- #include <algorithm>
- #include <iostream>
- #include <functional>
- using namespace std;
- struct Point {
- int x, y;
- } points[60];
- bool cmpCoord(Point a, Point b) {
- return a.y == b.y ? a.x < b.x : a.y > b.y;
- }
- int len2(Point a, Point b) {
- return (b.x - a.x) * (b.x - a.x) + (b.y - a.y) * (b.y - a.y);
- }
- int area(Point a, Point b, Point c) {
- return (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);
- }
- bool cmpAngle(Point a, Point b) {
- return area(points[0], a, b) == 0 ? len2(points[0], a) < len2(points[0], b) : area(points[0], a, b) < 0;
- }
- int p, n;
- vector<Point> hull;
- int main() {
- //freopen("input.txt", "r", stdin);
- //freopen("output.txt", "w", stdout);
- scanf("%d", &p);
- for (int tst = 1; tst <= p; tst++) {
- scanf("%*d%d", &n);
- for (int i = 0; i < n; i++)
- scanf("%d%d", &points[i].x, &points[i].y);
- sort(points, points + n, cmpCoord);
- sort(points + 1, points + n, cmpAngle);
- hull.clear();
- hull.push_back(points[0]);
- hull.push_back(points[1]);
- for (int i = 2; i < n; i++) {
- while (hull.size() > 1 && area(hull[hull.size() - 2], hull[hull.size() - 1], points[i]) >= 0)
- hull.pop_back();
- hull.push_back(points[i]);
- }
- printf("%d %d\n", tst, hull.size());
- for (int i = 0; i < hull.size(); i++)
- printf("%d %d\n", hull[i].x, hull[i].y);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement