POJ 2318 TOYS && POJ 2398 Toy Storage [判断点在四边形中]
来源:互联网 发布:mac outlook 默认字体 编辑:程序博客网 时间:2024/05/17 22:48
题目链接:http://poj.org/problem?id=2318
http://poj.org/problem?id=2398
题目的意思很简单,给你一个箱子,箱子里面有很多的隔板。然后给你一些点的坐标,让你统计每个四边形中有多少个点??直接判断点在四边形中就可以了。。
这两个题的意思都一样。。只是在输出上有的不同而已。。。2398题的隔板不是顺序给出的,所以需要排下序。。。很是easy。。比较简单。。
Code:2318
#include <iostream>#include <algorithm>#include <cstdio>#include <cstring>#include <cmath>using namespace std;#define CLR(arr, val) memset(arr, val, sizeof(arr))const int N = 5 * 1e3 + 5;const double eps = 1e-8;struct POINT{ double x, y; POINT(){ } POINT(double a, double b){ x = a; y = b; }};struct Segment{ POINT a, b; Segment() {} Segment(POINT x, POINT y){ a = x; b = y; }}seg[N];int ans[N], top;double cross(POINT o, POINT a, POINT b){ return (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x);}int find(POINT a){ for(int i = 1; i < top; i ++){ if(cross(a, seg[i - 1].a, seg[i - 1].b) * cross(a, seg[i].a, seg[i].b) <= 0) return i - 1; } return 0;}int main(){ int n, m; double x1, y1, x2, y2, x, y; bool flag = false; while(cin >> n && n){ cin >> m >> x1 >> y1 >> x2 >> y2; top = 0; seg[top ++] = Segment(POINT(x1, y1), POINT(x1, y2)); for(int i = 0; i < n; i ++){ cin >> x >> y; seg[top ++] = Segment(POINT(x, y1), POINT(y, y2)); } seg[top ++] = Segment(POINT(x2, y1), POINT(x2, y2)); CLR(ans, 0); for(int i = 0; i < m; i ++){ cin >> x >> y; ans[find(POINT(x, y))] ++; } if(flag) puts(""); for(int i = 0; i <= n; i ++){ cout << i <<": " << ans[i] << endl; } flag = true; } return 0;}
对于判断,点在四边形内。。对于这两个问题还是比较简单的。因为给出的点一定是在四边形内的。只需要判断在哪个四边形内就好了。。所以还是比较简单的。。。。
如果对于一个随意的四边形和一个随意的点,需要判断该点是否在该四边形内。。没给对应边都应该判断的。。
比如:下图,自己画 的有点挫。。
0 0
- POJ 2318 TOYS && POJ 2398 Toy Storage [判断点在四边形中]
- POJ 2398 Toy Storage(判定点在四边形内)
- POJ 2318 TOYS && POJ 2398 Toy Storage
- POJ 2318 TOYS || POJ 2398 Toy Storage
- poj 2398 Toy Storage(叉积判断点是否在四边形内)
- POJ 2318 TOYS + POJ 2398 Toy Storage (点与直线的位置关系)
- poj 2318 TOYS & poj 2398 Toy Storage (叉积)
- 【叉积性质】POJ 2318 TOYS && POJ 2398 Toy Storage
- POJ 2318:TOYS & POJ 2398:Toy Storage 计算几何
- poj 2398 Toy Storage(判断点在多边形内,叉积)
- poj 2398 Toy Storage(判断点在多边形内,叉积)
- poj 2318 TOYS(叉积判断点是否在四边形内)
- POJ2318 TOYS 和POJ2398 Toy Storage题解(点在四边形内)(简单几何)
- POJ 2398 Toy Storage (判断点与线段关系)
- poj 2398 Toys storage
- POJ 2318 TOYS + 2398 Toy Storage(计算几何叉积)
- poj 2398 Toy Storage
- poj 2398 Toy Storage
- rapidxml查找结点内相同结点标签的内容
- 计之伊始
- 费曼先生 找数学家“麻烦”
- 网络流专栏
- Play Framework Web开发教程(33): 结构化页面-组合使用模板
- POJ 2318 TOYS && POJ 2398 Toy Storage [判断点在四边形中]
- Python 清空列表
- 手机安全卫士(1)--启动画面全屏显示&动画加载&版本号
- YUV (Come form WIKI)
- 解决客户端因google被墙导致访问一些网站慢的问题
- 电商企业如何选择电商ERP
- 角点检测
- TCP/IP、Http、Socket的区别
- Servlet之二 —— HttpServlet的doGet()和doPost()