跨产品的利用率推断点线段向左或向右,然后你可以2分钟

代码:

  1. #include <cstdio>
  2. #include <cstring>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. const int N = 5005;
  7.  
  8. int n, m, x1, y1, x2, y2;
  9.  
  10. struct Point {
  11. int x, y;
  12. Point() {}
  13. Point(int x, int y) {
  14. this->x = x;
  15. this->y = y;
  16. }
  17. };
  18.  
  19. typedef Point Vector;
  20.  
  21. Vector operator - (Vector A, Vector B) {
  22. return Vector(A.x - B.x, A.y - B.y);
  23. }
  24.  
  25. struct Seg {
  26. Point a, b;
  27. Seg() {}
  28. Seg(Point a, Point b) {
  29. this->a = a;
  30. this->b = b;
  31. }
  32. } seg[N];
  33.  
  34. int ans[N];
  35.  
  36. int Cross(Vector A, Vector B) {return A.x * B.y - A.y * B.x;}
  37.  
  38. void gao(Point p) {
  39. int l = 0, r = n;
  40. while (l < r) {
  41. int mid = (l + r) / 2;
  42. if (Cross(seg[mid].a - p, seg[mid].b - p) < 0) r = mid;
  43. else l = mid + 1;
  44. }
  45. ans[l]++;
  46. }
  47.  
  48. int main() {
  49. while (~scanf("%d", &n) && n) {
  50. memset(ans, 0, sizeof(ans));
  51. scanf("%d%d%d%d%d", &m, &x1, &y1, &x2, &y2);
  52. int x, y;
  53. for (int i = 0; i < n; i++) {
  54. scanf("%d%d", &x, &y);
  55. seg[i] = Seg(Point(x, y1), Point(y, y2));
  56. }
  57. for (int i = 0; i < m; i++) {
  58. scanf("%d%d", &x, &y);
  59. gao(Point(x, y));
  60. }
  61. for (int i = 0; i <= n; i++)
  62. printf("%d: %d\n", i, ans[i]);
  63. printf("\n");
  64. }
  65. return 0;
  66. }

POJ 2318 TOYS(计算几何)的更多相关文章

  1. poj 2318 TOYS(计算几何 点与线段的关系)

    TOYS Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 12015   Accepted: 5792 Description ...

  2. POJ 2318 TOYS(叉积+二分)

    题目传送门:POJ 2318 TOYS Description Calculate the number of toys that land in each bin of a partitioned ...

  3. poj 2318 TOYS (二分+叉积)

    http://poj.org/problem?id=2318 TOYS Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 101 ...

  4. 简单几何(点与线段的位置) POJ 2318 TOYS && POJ 2398 Toy Storage

    题目传送门 题意:POJ 2318 有一个长方形,用线段划分若干区域,给若干个点,问每个区域点的分布情况 分析:点和线段的位置判断可以用叉积判断.给的线段是排好序的,但是点是无序的,所以可以用二分优化 ...

  5. POJ 2318 TOYS && POJ 2398 Toy Storage(几何)

    2318 TOYS 2398 Toy Storage 题意 : 给你n块板的坐标,m个玩具的具体坐标,2318中板是有序的,而2398无序需要自己排序,2318要求输出的是每个区间内的玩具数,而231 ...

  6. 向量的叉积 POJ 2318 TOYS & POJ 2398 Toy Storage

    POJ 2318: 题目大意:给定一个盒子的左上角和右下角坐标,然后给n条线,可以将盒子分成n+1个部分,再给m个点,问每个区域内有多少各点 这个题用到关键的一步就是向量的叉积,假设一个点m在 由ab ...

  7. poj 2318 TOYS &amp; poj 2398 Toy Storage (叉积)

    链接:poj 2318 题意:有一个矩形盒子,盒子里有一些木块线段.而且这些线段坐标是依照顺序给出的. 有n条线段,把盒子分层了n+1个区域,然后有m个玩具.这m个玩具的坐标是已知的,问最后每一个区域 ...

  8. 【POJ】2318 TOYS ——计算几何+二分

    TOYS Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 10281   Accepted: 4924 Description ...

  9. 2018.07.03 POJ 2318 TOYS(二分+简单计算几何)

    TOYS Time Limit: 2000MS Memory Limit: 65536K Description Calculate the number of toys that land in e ...

随机推荐

  1. MVC:Controller向View传值方式总结

    Controller向View传值方式总结 总结发现ASP.NET MVC中Controller向View传值的方式共有6种,分别是: ViewBag ViewData TempData 向普通Vie ...

  2. Python基础入门教程

    Python基础入门教程 Python基础教程 Python 简介 Python环境搭建 Python 基础语法 Python 变量类型 Python 运算符 Python 条件语句 Python 循 ...

  3. ORA-01092 ORA-12432: LBAC error: zllegnp:OCIStmtExecute 故障一例

    最近由于数据库hang住,无奈之下直接干掉了pmon进程,再次启动的时候收到了ORA-01092: ORACLE instance terminated. Disconnection forced以及 ...

  4. sharepoint 2013 根据网站模版创建网站,并赋值网站权限 create a site by custom site template

    通过程序,根据网站模版,创建新的网站 private void CreateSiteBySiteTemplate() { SPSecurity.RunWithElevatedPrivileges(de ...

  5. 黑马程序猿_Objective C 类与协议

    <a href="http://www.itheima.com"target="blank">ASP.Net+Unity开发</a>.& ...

  6. sqlserver bak还原

    一.查看: restore filelistonly from disk='F:\Db\A_backup.bak' 二.还原:RESTORE DATABASE AFROM DISK = 'F:\Db\ ...

  7. 图片组件——axure线框图部件库介绍

    我们在后面的组件使用中,都统一使用"从部件区域拖拽图片组件到页面区域中" 1. 图片载入 1.1 将图片组件拖拽到页面区域 1.2 双击图片组件 1.3 选择合适图片,点击打开 1 ...

  8. android 使用Scroller实现缓慢移动

    在Launcher中的Workspace中实现了左右屏幕切换效果,里面就用到了Scroller记录滑动轨迹,实现一种缓慢地向左或向右移动的效果,这里我对这种效果进行总结: 我们先看一个例子:点击按钮时 ...

  9. Eclipse TestNg插件

    TestNg作为一个测试框架,也有eclipse的插件: 官网给的安装插件地址是 : For Eclipse 3.4 and above, enter http://beust.com/eclipse ...

  10. spring mvc接收JSON格式的参数

    1.配置spring解析json的库   <dependency>         <groupId>org.codehaus.jackson</groupId> ...