poj 2398 Toy Storage(计算几何:叉积)
2014-12-01 22:05
501 查看
基本上和poj 2318一模一样。。。
改下输出就可以了
代码如下:
改下输出就可以了
代码如下:
/* *********************************************** Author :yinhua Created Time :2014年12月01日 星期一 19时25分15秒 File Name :poj2398.cpp ************************************************ */ #include <cmath> #include <cstdio> #include <string> #include <cstring> #include <iostream> #include <algorithm> #define MAXN 100010 #define LL long long using namespace std; struct Point { int x, y; Point() { } Point(int _x, int _y) { x = _x;y = _y; } Point operator -(const Point &b) const { return Point(x-b.x, y-b.y); } int operator *(const Point &b) const { return x*b.x+y*b.y; } int operator ^(const Point &b) const { return x*b.y-y*b.x; } }; struct Line { Point s, e; Line() { } Line(Point _s, Point _e) { s = _s; e = _e; } }; bool cmp(Line a, Line b) { return (a.s).x < (b.s).x; } int xmult(Point p0, Point p1, Point p2) {//p0点与线段p1 p2的叉积 return (p1-p0)^(p2-p0); } Line line[MAXN]; int res[MAXN]; int ans[MAXN]; int main(void) { int m, n, x1, y1, x2, y2; bool first = true; while(~scanf("%d", &n) && n) { scanf("%d%d%d%d%d", &m, &x1, &y1, &x2, &y2); int ui, li; for(int i=0; i<n; ++i) { scanf("%d%d", &ui, &li); line[i] = Line(Point(ui, y1), Point(li, y2)); } sort(line, line+n, cmp); line = Line(Point(x2, y1), Point(x2, y2)); int x, y; Point p; memset(ans, 0, sizeof(ans)); for(int i=1; i<=m; ++i) { scanf("%d%d", &x, &y); p = Point(x, y); int l = 0, r = n; int tmp; while(l <= r) { int mid = (l+r)>>1; if(xmult(p, line[mid].s, line[mid].e) < 0) {//点在当前线的左侧 tmp = mid; r = mid-1; } else l = mid+1;//点在当前线的右侧 } ans[tmp]++; } memset(res, 0, sizeof(res)); for(int i=0; i<=n; ++i) { if(ans[i]) ++res[ans[i]]; } bool ok = true; for(int i=1; i<=m; ++i) { if(res[i]) { if(ok) { ok = false; puts("Box"); } printf("%d: %d\n", i, res[i]); } } } return 0; }
相关文章推荐
- 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 【计算几何】【点和线的关系】
- POJ2398_Toy Storage(几何/叉积运用)
- 7_4_P题 Toy Storage 题解[Poj 2398](计算几何,点线关系,二分)
- poj2398——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 2318:TOYS & POJ 2398:Toy Storage 计算几何
- POJ 2398 Toy Storage(计算几何)