TOYS
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 17974   Accepted: 8539

Description

Calculate the number of toys that land in each bin of a partitioned toy box. 
Mom and dad have a problem - their child John never puts his toys away when he is finished playing with them. They gave John a rectangular box to put his toys in, but John is rebellious and obeys his parents by simply throwing his toys into the box. All the toys get mixed up, and it is impossible for John to find his favorite toys.

John's parents came up with the following idea. They put cardboard partitions into the box. Even if John keeps throwing his toys into the box, at least toys that get thrown into different bins stay separated. The following diagram shows a top view of an example toy box. 
 
For this problem, you are asked to determine how many toys fall into each partition as John throws them into the toy box.

Input

The input file contains one or more problems. The first line of a problem consists of six integers, n m x1 y1 x2 y2. The number of cardboard partitions is n (0 < n <= 5000) and the number of toys is m (0 < m <= 5000). The coordinates of the upper-left corner and the lower-right corner of the box are (x1,y1) and (x2,y2), respectively. The following n lines contain two integers per line, Ui Li, indicating that the ends of the i-th cardboard partition is at the coordinates (Ui,y1) and (Li,y2). You may assume that the cardboard partitions do not intersect each other and that they are specified in sorted order from left to right. The next m lines contain two integers per line, Xj Yj specifying where the j-th toy has landed in the box. The order of the toy locations is random. You may assume that no toy will land exactly on a cardboard partition or outside the boundary of the box. The input is terminated by a line consisting of a single 0.

Output

The output for each problem will be one line for each separate bin in the toy box. For each bin, print its bin number, followed by a colon and one space, followed by the number of toys thrown into that bin. Bins are numbered from 0 (the leftmost bin) to n (the rightmost bin). Separate the output of different problems by a single blank line.

Sample Input

5 6 0 10 60 0
3 1
4 3
6 8
10 10
15 30
1 5
2 1
2 8
5 5
40 10
7 9
4 10 0 10 100 0
20 20
40 40
60 60
80 80
5 10
15 10
25 10
35 10
45 10
55 10
65 10
75 10
85 10
95 10
0

Sample Output

0: 2
1: 1
2: 1
3: 1
4: 0
5: 1 0: 2
1: 2
2: 2
3: 2
4: 2

Hint

As the example illustrates, toys that fall on the boundary of the box are "in" the box.

Source

 
  1. 题意:给n条边,划分成n+1个区域,再给定m个点坐标,点不会落在边界上和区域外,问每个区域中各自存在多少个点
  2. 代码如下  
     #include<iostream>
    #include<cstring>
    #include<string>
    #include<algorithm>
    #include<vector>
    #include<stack>
    #include<bitset>
    #include<cstdio>
    #include<cstdlib>
    #include<cmath>
    #include<set>
    #include<list>
    #include<deque>
    #include<map>
    #include<queue>
    using namespace std;
    const int MAX = ; typedef struct point {
    int x;
    int y;
    }point;
    typedef struct value {
    point start;
    point end;
    }v;
    v edge[MAX];
    int sum[MAX];
    int n, m, x1, y11, x2, y2, flag = ;
    point tp;
    int Xj, Yj;
    int multi(point p1, point p2, point p0) { //判断p1p0和p2p0的关系,<0,p1p0在p2p0的逆时针方向
    return (p1.x - p0.x)*(p2.y - p0.y) - (p2.x - p0.x)*(p1.y - p0.y);
    }
    void inset(point p) {
    int low = , high = n;
    while (low <= high) {
    int mid = (high + low) / ;
    if (multi(p, edge[mid].start, edge[mid].end) < ) /*点p1在边的左侧*/
    high = mid - ;
    else //点p在边的右侧
    low = mid + ;
    }
    if (multi(p, edge[low-].start, edge[low-].end) < )
    sum[low-]++;
    else
    sum[low]++;
    }
    int main() {
    while (~scanf("%d", &n) && n) {
    memset(sum, , sizeof(sum));
    if (flag == )flag++;
    else printf("\n");
    scanf("%d%d%d%d%d", &m, &x1, &y11, &x2, &y2);
    int Ui, Li;
    for (int i = ; i < n; i++) {
    scanf("%d%d", &Ui, &Li);
    edge[i].start.x = Ui;
    edge[i].start.y = y11;
    edge[i].end.x = Li;
    edge[i].end.y = y2;
    }
    edge[n].start.x = x2;
    edge[n].start.y = y11;
    edge[n].end.x = x2;
    edge[n].end.y = y2;
    for (int j = ; j < m; j++) {
    scanf("%d%d", &Xj, &Yj);
    tp.x = Xj;
    tp.y = Yj;
    inset(tp);
    }
    for (int i = ; i <= n; i++)
    printf("%d: %d\n", i, sum[i]);
    }
    return ;
    }
  3. Experience: 前面点的构造写成

     edge[i].start = { Ui,y11 };
    edge[i].end = { Li,y2 };

    当发现这个错误的时候,我自己都被自己蠢哭了,Wa了2页,一直以为是叉积方向搞错了,原来不是ORZ

  4. 这个是我真正意义上第一道计算几何,mark一下。

POJ 2318--TOYS(二分找点,叉积判断方向)的更多相关文章

  1. POJ 2318 TOYS (计算几何,叉积判断)

    TOYS Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 8661   Accepted: 4114 Description ...

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

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

  3. POJ 2318 TOYS | 二分+判断点在多边形内

    题意: 给一个矩形的区域(左上角为(x1,y1) 右下角为(x2,y2)),给出n对(u,v)表示(u,y1) 和 (v,y2)构成线段将矩形切割 这样构成了n+1个多边形,再给出m个点,问每个多边形 ...

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

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

  5. POJ 2318 TOYS(点与直线的关系 叉积&&二分)

    题目链接 题意: 给定一个矩形,n个线段将矩形分成n+1个区间,m个点,问这些点的分布. 题解: 思路就是叉积加二分,利用叉积判断点与直线的距离,二分搜索区间. 代码: 最近整理了STL的一些模板,发 ...

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

    题目: Description Calculate the number of toys that land in each bin of a partitioned toy box. Mom and ...

  7. POJ 2318 TOYS【叉积+二分】

    今天开始学习计算几何,百度了两篇文章,与君共勉! 计算几何入门题推荐 计算几何基础知识 题意:有一个盒子,被n块木板分成n+1个区域,每个木板从左到右出现,并且不交叉. 有m个玩具(可以看成点)放在这 ...

  8. POJ 2318 TOYS 利用叉积判断点在线段的那一侧

    题意:给定n(<=5000)条线段,把一个矩阵分成了n+1分了,有m个玩具,放在为位置是(x,y).现在要问第几个位置上有多少个玩具. 思路:叉积,线段p1p2,记玩具为p0,那么如果(p1p2 ...

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

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

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

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

随机推荐

  1. django中自定义表名及字段名称

    在meta 类中指定表名,在字段中通过db_column指定列名如下所示 class Record(models.Model): content=models.CharField(max_length ...

  2. 希尔排序——Java实现

    一.排序思想 希尔排序(Shell’s Sort)是插入排序的一种,是直接插入排序算法的一种更高版本的改进版本. 把记录按步长gap分组,对每组记录采用直接插入排序方法进行排序: 随着步长逐渐减小,所 ...

  3. Hadoop2.x伪分模式部署

    hadoop伪分布模式,只有一个节点,通常用来做测试. 一.环境准备 Linux网络配置已完成,可参见CentOS7网络配置: yum源成功挂载,可参见CentOS7本地yum源挂载: Linux已安 ...

  4. flex布局帮助你快速实现布局

    flex布局可以帮我们快速布局一些区块,实现你想要的效果,不用再去float,position之类的.我们在布局网页的时候很多时候都是一些特殊布局,flex就能帮我快速去布局,不需要去定位. 任何一个 ...

  5. 18_Condition条件

    [简述] wait()和notify()方法是和synchronized关键字合作使用的. Condition是和重入锁相关联的,通过ReentrantLock.newCondition()生成一个与 ...

  6. 在Eclipse安装Genymotion插件的经验心得

    个人心得分享,不当之处还请指正. Eclipse自带的Android模拟器已经无力吐槽了,新手刚上手时或许配置完环境已经精疲力尽了,或许还沉浸在开发成功的喜悦当中,对AVD模拟器的运行情况关注不大,渐 ...

  7. 【IOS】Mac和IOS开发资源汇总

    本文主要汇集一些苹果开发的资源,会经常更新,建议大家把这篇文章单独收藏(在浏览器中按**command+D**). 今天收录了许多中文网站和博客.大家一定要去感受一下哦. 如果大家有知道不错的站点,可 ...

  8. JS高级程序设计第三版——在HTML中使用JavaScript

    使用<script>元素的方式 外部引用式.行内式.嵌入式. JavaScript引用放在<body>后面的原因 假如在文档的<head>元素中包含所有JavaSc ...

  9. C#实现文件异步上传

    //前台方法,包含弹出框确认以及文件选择<input type="button" id="importxlsx" name="importxls ...

  10. 使用pm2自动化部署node项目

    1.pm2简介 pm2(process manager)是一个进程管理工具,维护一个进程列表,可以用它来管理你的node进程,负责所有正在运行的进程,并查看node进程的状态,也支持性能监控,负载均衡 ...