您的位置:首页
POJ 2398 Toy Storage(计算几何)
2017-07-29 09:46
447 查看
和POJ2318一样的方法,都是利用叉积推断+二分。只是这题要先排序。还有输出的是,每一个数量的格子数
代码:
代码:
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int N = 1005; int n, m, x1, y1, x2, y2; struct Point { int x, y; Point() {} Point(int x, int y) { this->x = x; this->y = y; } }; typedef Point Vector; Vector operator - (Vector A, Vector B) { return Vector(A.x - B.x, A.y - B.y); } struct Seg { Point a, b; Seg() {} Seg(Point a, Point b) { this->a = a; this->b = b; } } seg ; int ans ; int Cross(Vector A, Vector B) {return A.x * B.y - A.y * B.x;} void gao(Point p) { int l = 0, r = n; while (l < r) { int mid = (l + r) / 2; if (Cross(seg[mid].a - p, seg[mid].b - p) < 0) r = mid; else l = mid + 1; } ans[l]++; } bool cmp(Seg a, Seg b) { return a.a.x < b.a.x; } int out ; int main() { while (~scanf("%d", &n) && n) { memset(ans, 0, sizeof(ans)); scanf("%d%d%d%d%d", &m, &x1, &y1, &x2, &y2); int x, y; for (int i = 0; i < n; i++) { scanf("%d%d", &x, &y); seg[i] = Seg(Point(x, y1), Point(y, y2)); } sort(seg, seg + n, cmp); for (int i = 0; i < m; i++) { scanf("%d%d", &x, &y); gao(Point(x, y)); } memset(out, 0, sizeof(out)); for (int i = 0; i <= n; i++) if (ans[i]) out[ans[i]]++; printf("Box\n"); for (int i = 1; i <= 1000; i++) if (out[i]) printf("%d: %d\n", i, out[i]); } return 0; }
相关文章推荐
- POJ 2318:TOYS & POJ 2398:Toy Storage 计算几何
- poj2398——Toy Storage(计算几何)
- POJ--2398 -- Toy Storage [计算几何]
- 7_4_P题 Toy Storage 题解[Poj 2398](计算几何,点线关系,二分)
- POJ 2398 Toy Storage(计算几何)
- POJ 2318 TOYS + 2398 Toy Storage(计算几何叉积)
- poj 2398 Toy Storage(计算几何 点线关系)
- POJ 2398 Toy Storage(计算几何,叉积判断点和线段的关系)
- poj 2398 Toy Storage(计算几何)
- poj 2398 Toy Storage (计算几何)
- poj 2398 Toy Storage (计算几何)
- POJ 2398 Toy Storage 计算几何(点与直线的关系)
- POJ - 2398 Toy Storage(计算几何)
- poj 2398 Toy Storage 【计算几何】【点和线的关系】
- POJ 2398 Toy Storage(计算几何)
- poj 2398 Toy Storage (计算几何,判断点和线段关系)
- poj 2398 Toy Storage(计算几何,点跟直线的位置关系)
- poj 2398 Toy Storage (计算几何)
- poj 2398 Toy Storage 计算几何+二分
- B - Toy Storage(POJ - 2398) 计算几何基础题,比TOYS多了个线段排序