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 {
- double x, y;
- Point(double X = 0, double Y = 0) : x(X), y(Y) {}
- } points[60];
- bool between(double v, double a, double b) {
- return (a <= v && v <= b) || (a >= v && v >= b);
- }
- pair<bool, double> inter(Point a, Point b, double y) {
- double x = a.x + (y - a.y) * (b.x - a.x) / (b.y - a.y);
- return make_pair(between(x, a.x, b.x) && between(y, a.y, b.y), x);
- }
- int p, n, maxY, minY;
- map<int, pair<int, int> > ans;
- int main() {
- //freopen("input.txt", "r", stdin);
- //freopen("output.txt", "w", stdout);
- scanf("%d", &p);
- for (int tst = 1; tst <= p; tst++) {
- ans.clear();
- scanf("%*d%d", &n);
- for (int i = 0; i < n; i++) {
- scanf("%lf%lf", &points[i].x, &points[i].y);
- if (i == 0)
- minY = maxY = points[i].y;
- minY = min(minY, (int)points[i].y);
- maxY = max(maxY, (int)points[i].y);
- }
- for (int y = maxY - 1; y > minY; y--) {
- vector<double> line;
- for (int i = 0; i < n; i++) {
- pair<bool, double> ix = inter(points[i], points[(i + 1) % n], y);
- if (ix.first)
- line.push_back(ix.second);
- }
- sort(line.begin(), line.end());
- if (!line.empty() && ceil(*line.begin() + 1e-12) <= floor(*line.rbegin() - 1e-12))
- ans.insert(make_pair(y, make_pair(ceil(*line.begin() + 1e-12), floor(*line.rbegin() - 1e-12))));
- }
- printf("%d %d\n", tst, ans.size());
- for (map<int, pair<int, int> >::reverse_iterator i = ans.rbegin(); i != ans.rend(); i++)
- printf("%d %d %d\n", i->first, i->second.first, i->second.second);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement