POJ 2318 TOYS(计算几何)
2015-06-20 16:47
387 查看
跨产品的利用率推断点线段向左或向右,然后你可以2分钟
代码:
代码:
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int N = 5005; int n, m, x1, y1, x2, y2; struct Point { int x, y; Point() {} Point(int x, int y) { this->x = x; this->y = y; } }; typedef Point Vector; Vector operator - (Vector A, Vector B) { return Vector(A.x - B.x, A.y - B.y); } struct Seg { Point a, b; Seg() {} Seg(Point a, Point b) { this->a = a; this->b = b; } } seg ; int ans ; int Cross(Vector A, Vector B) {return A.x * B.y - A.y * B.x;} void gao(Point p) { int l = 0, r = n; while (l < r) { int mid = (l + r) / 2; if (Cross(seg[mid].a - p, seg[mid].b - p) < 0) r = mid; else l = mid + 1; } ans[l]++; } int main() { while (~scanf("%d", &n) && n) { memset(ans, 0, sizeof(ans)); scanf("%d%d%d%d%d", &m, &x1, &y1, &x2, &y2); int x, y; for (int i = 0; i < n; i++) { scanf("%d%d", &x, &y); seg[i] = Seg(Point(x, y1), Point(y, y2)); } for (int i = 0; i < m; i++) { scanf("%d%d", &x, &y); gao(Point(x, y)); } for (int i = 0; i <= n; i++) printf("%d: %d\n", i, ans[i]); printf("\n"); } return 0; }
相关文章推荐
- android中的五大布局和过程流向
- MapReduce程序之实现单表关联
- PHP 判断数据类型
- 《你的灯亮着吗》阅读笔记3
- 尾递归与Continuation
- 八大排序算法总结之一(冒泡排序,快速排序,直接插入排序,希尔排序)
- windows安装php5.6和apache2.4,相对于老版本的一些新的变动
- 函数调用约定
- Redis内部数据结构详解之压缩链表(ziplist)
- LeetCode之“散列表”:Single Number
- SPOJ NSUBSTR
- 谷歌搜索 site命令 指定网站搜索
- oracle12c ORA-28040: No matching authentication protocol错误
- SQL server 2005基本操作
- fedora实现多版本gcc共享
- Windows 7 64位安装Oracle XE(32位)数据库报错等解决方案
- 浙江大学PAT_甲级_1058. A+B in Hogwarts (20)
- leetcode--Binary Tree Right Side View
- sgu276:Andrew's Troubles(大大大水题)
- 创业公司如何实施敏捷开发