POJ 2318 TOYS(几何)
来源:互联网 发布:国际阿里云200m多少钱 编辑:程序博客网 时间:2024/06/07 09:59
题目链接:POJ 2318 TOYS
用点积判断一个点在直线的哪一侧,由于题目给出的分割线是排序后的,那么可以直接用二分得出答案。
#include <iostream>#include <cstdio>#include <cmath>#include <cstring>using namespace std;const double eps = 1e-10;const int MAX_N = 5000 + 10;struct Point{double x, y;Point(double x=0, double y=0):x(x),y(y) { }};typedef Point Vector;Vector operator + (const Vector& A, const Vector& B){ return Vector(A.x+B.x, A.y+B.y);}Vector operator - (const Point& A, const Point& B){ return Vector(A.x-B.x, A.y-B.y);}Vector operator * (const Vector& A, double p){ return Vector(A.x*p, A.y*p);}bool operator < (const Point& a, const Point& b){return a.x < b.x || (a.x == b.x && a.y < b.y);}int dcmp(double x){ if(fabs(x) < eps) return 0; else return x < 0 ? -1 : 1;}bool operator == (const Point& a, const Point &b){return dcmp(a.x-b.x) == 0 && dcmp(a.y-b.y) == 0;}double Cross(const Vector& A, const Vector& B){ return A.x*B.y - A.y*B.x;}Point p[MAX_N << 1];Point bound[3];Point toy;int _count[MAX_N];int n, m;void b_search(){ int l = 0, r = n - 1, mid; while(l <= r) { mid = (l + r) >> 1; if(Cross(toy - p[mid], p[mid + n] - p[mid]) > 0) r = mid - 1; else if(Cross(toy - p[mid], p[mid + n] - p[mid]) < 0) l = mid + 1; } _count[r + 1]++;}int main(){ //freopen("in.txt", "r", stdin); while(scanf("%d", &n), n) { memset(_count, 0, sizeof(_count)); scanf("%d", &m); scanf("%lf%lf%lf%lf", &bound[0].x, &bound[0].y, &bound[2].x, &bound[2].y); for(int i = 0; i < n; i++) { scanf("%lf%lf",&p[i].x, &p[i + n].x); p[i].y = bound[0].y; p[i + n].y = bound[2].y; } for(int i = 0; i < m; i++) { scanf("%lf%lf", &toy.x, &toy.y); b_search(); } for(int i = 0; i <= n; i++) printf("%d: %d\n", i, _count[i]); printf("\n"); } return 0;}
0 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(计算几何)
- poj 2318 TOYS(计算几何:求叉积)
- Poj 2318 toys (计算几何,叉积)
- POJ 2318 TOYS(计算几何)
- POJ 2318 - TOYS【计算几何 - 叉积】
- POJ 2318 TOYS 几何题 基础
- POJ 2318 TOYS 计算几何 线段相交
- POJ 2318 TOYS(计算几何入门)
- poj 2318 TOYS(计算几何)
- 【POJ 2318】TOYS(计算几何)
- POJ 2318 TOYS(计算几何)
- 取绝对值 :abs fabs fabsf用法
- Linux文件同步方法(rsync及scp)
- caffe源码分析--math_functions.cu代码研究
- Hadoop版本及cloudera的CDH3 CDH4
- 亚泰盛世携NB物理实验邀你莅临第66届中国教育装备展
- POJ 2318 TOYS(几何)
- js function injector
- 在Qt Creator中使用OpenCV库
- NO_30Digit fifth powers
- 教你用Cocosdx导出安卓安装文件(.apk)(二)
- cocos2d-x 添加 广告
- sql server2008 字段类型详解
- 转(Android 4.4 Kitkat Phone工作流程浅析(三)__MO(去电)流程分析)
- python的socket编程