poj 2398 Toy Storage(计算几何:叉积)
来源:互联网 发布:软件服务行业 编辑:程序博客网 时间:2024/05/18 02:17
基本上和poj 2318一模一样。。。
改下输出就可以了
代码如下:
/* ***********************************************Author :yinhuaCreated 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 longusing 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[n] = 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; }
0 0
- 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 2318:TOYS & POJ 2398:Toy Storage 计算几何
- POJ 2398 Toy Storage(几何)
- Poj 2398 Toy Storage(几何)
- poj 2398 Toy Storage(计算几何,点跟直线的位置关系)
- POJ 2398 Toy Storage 计算几何(点与直线的关系)
- POJ 2318 TOYS + 2398 Toy Storage(计算几何叉积)
- POJ 2398 Toy Storage(计算几何,叉积判断点和线段的关系)
- Toy Storage(二维计算几何基础)
- mac安装redis
- 函数版5个数的升序降序
- 简单的人品计算器
- Java设计模式之Builder和Decorator
- 观余佳文之后
- poj 2398 Toy Storage(计算几何:叉积)
- fzu 2105——Digits Count
- MapReduce: 提高MapReduce性能的七点建议[译]
- linux 系统性能指标
- 枚举类型
- Java学习day09
- Java 平台AOP
- 输出0到n(含)中数字2出现了几次。
- CVE-2014-6332调试分析