POJ 2318 TOYS 二分+叉积
来源:互联网 发布:淘宝新店装修教程 编辑:程序博客网 时间:2024/06/06 00:47
入门计算几何
判断在哪个区域内只需看跟某条线的叉积即可
可以保证单调性,所以可以进行二分
#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <algorithm>#include <cstdlib>#include <cmath>#include <map>#include <sstream>#include <queue>#include <vector>#define MAXN 100001#define MAXM 211111#define eps 1e-8#define INF 500000001using namespace std;int dblcmp(double d){ if(fabs(d) < eps) return 0; return d > eps ? 1 : -1;}struct point{ double x, y; point(){} point(double _x, double _y): x(_x), y(_y) {}; void input() { scanf("%lf%lf", &x, &y); } void output() { printf("%.2f %.2f\n", x, y); } double det(point p) { return x * p.y - y * p.x; } point sub(point p) { return point(x - p.x, y - p.y); }}up[5555], down[5555];double getcross(point a, point o, point b){ a = a.sub(o); b = b.sub(o); return a.det(b);}int num[5555];int n, m;int main(){ double xa, xb, ya, yb, ui, li; int cas = 0; while(scanf("%d", &n) != EOF && n) { scanf("%d%lf%lf%lf%lf", &m, &xa, &ya, &xb, &yb); if(cas++) puts(""); up[0] = point(xa, ya); down[0] = point(xa, yb); for(int i = 1; i <= n; i++) { scanf("%lf%lf", &ui, &li); up[i] = point(ui, ya); down[i] = point(li, yb); } up[n + 1] = point(xb, ya); down[n + 1] = point(xb, yb); memset(num, 0, sizeof(num)); point tmp; for(int i = 0; i < m; i++) { tmp.input(); int low = 0, high = n + 1; while(low <= high) { int mid = (low + high) >> 1; if(dblcmp(getcross(up[mid], tmp, down[mid])) > 0) low = mid + 1; else high = mid - 1; } num[low - 1] ++; } for(int i = 0; i <= n; i++) printf("%d: %d\n", i, num[i]); } return 0;}
- Poj 2318 TOYS (叉积+二分)
- POJ 2318 TOYS 二分+叉积
- poj 2318 TOYS 二分+叉积
- poj 2318 TOYS 二分+叉积
- POJ 2318 TOYS(叉积+二分)
- poj 2318 TOYS(叉积+二分)
- POJ 2318 TOYS(叉积+二分查找)
- poj 2318 TOYS(叉积+二分)
- TOYS (poj 2381 叉积+二分)
- POJ 2318 TOYS 计算几何 入门题 叉积 + 二分
- POJ 2318 TOYS(叉积+二分or暴力)
- POJ 2318 —— TOYS(叉积+二分)
- TOYS - POJ 2318 叉积
- poj 2318 TOYS (叉积)
- POJ 2318 TOYS 叉积运算+二分
- poj 2318 toys 计算几何+二分
- POJ 2318 TOYS 【二分】【点线关系】
- POJ-2318 TOYS 【向量叉积+二分】
- ios(一) OC基础
- C内存相关的题目总结
- struts2 备忘录
- 遇到问题
- 近邻成分分析(NCA)算法
- POJ 2318 TOYS 二分+叉积
- 多重panel的边框效果
- ListView异步加载图片是非常实用的方法,凡是是要通过网络获取图片资源一般使用这种方法比较好,用户体验好,下面就说实现方法,先贴上主方法的代码:
- 【SGA】sga的物理分配
- 黑马程序员--方法参数传递的方式
- 写这篇文章并不是教大家怎么样用listview异步加载图片,因为这样的文章在网上已经有很多了,比如这位仁兄写的就很好
- ThinkPad家族全系列解析
- SQL优化
- sqlmap常用命令