Toy Storage

Time Limit: 1000MS Memory Limit: 65536K

Description

Mom and dad have a problem: their child, Reza, never puts his toys away when he is finished playing with them. They gave Reza a rectangular box to put his toys in. Unfortunately, Reza 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 Reza to find his favorite toys anymore.

Reza’s parents came up with the following idea. They put cardboard partitions into the box. Even if Reza keeps throwing his toys into the box, at least toys that get thrown into different partitions stay separate. The box looks like this from the top:



We want for each positive integer t, such that there exists a partition with t toys, determine how many partitions have t, toys.

Input

The input consists of a number of cases. The first line consists of six integers n, m, x1, y1, x2, y2. The number of cardboards to form the partitions is n (0 < n <= 1000) and the number of toys is given in m (0 < m <= 1000). 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 each consists of two integers Ui Li, indicating that the ends of the ith cardboard is at the coordinates (Ui, y1) and (Li, y2). You may assume that the cardboards do not intersect with each other. The next m lines each consists of two integers Xi Yi specifying where the ith toy has landed in the box. You may assume that no toy will land on a cardboard.

A line consisting of a single 0 terminates the input.

Output

For each box, first provide a header stating “Box” on a line of its own. After that, there will be one line of output per count (t > 0) of toys in a partition. The value t will be followed by a colon and a space, followed the number of partitions containing t toys. Output will be sorted in ascending order of t for each box.

Sample Input

4 10 0 10 100 0

20 20

80 80

60 60

40 40

5 10

15 10

95 10

25 10

65 10

75 10

35 10

45 10

55 10

85 10

5 6 0 10 60 0

4 3

15 30

3 1

6 8

10 10

2 1

2 8

1 5

5 5

40 10

7 9

0

Sample Output

Box

2: 5

Box

1: 4

2: 1

Source

Tehran 2003 Preliminary

这道题就是POJ2318的变体,也是一道简单计算几何,代码基本上也差不多,但本蒟蒻重敲的时候调一个小细节调了很久,其实这个问题还是so" role="presentation" style="position: relative;">soso easy" role="presentation" style="position: relative;">easyeasy的。注意到这道题的纸板没有顺序(本蒟蒻被坑的第一个点),然后请各位每次输入点时不要用while(m−−)" role="presentation" style="position: relative;">while(m−−)while(m−−)(本蒟蒻被坑的第二个点)。其他就没啥了,就一个二分答案+叉积判断就没了。

代码如下:

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
struct pot{int x,y;};
struct line{pot a,b;}l[1005];
int n,m,x1,x2,y1,y2,cnt[1005],tot[1005];
inline pot operator-(pot a,pot b){return pot{a.x-b.x,a.y-b.y};}
inline int cross(pot a,pot b){return a.x*b.y-a.y*b.x;}
inline bool check(int k,pot p){return cross(l[k].b-p,l[k].a-p)<0;}
inline bool cmp(line a,line b){return a.a.x<b.a.x;}
inline int search(pot p){
    int l=1,r=n;
    while(l<=r){
        int mid=l+r>>1;
        if(check(mid,p))l=mid+1;
        else r=mid-1;
    }
    return r;
}
int main(){
    while(scanf("%d",&n)&&n){
        memset(cnt,0,sizeof(cnt));
        memset(tot,0,sizeof(tot));
        scanf("%d%d%d%d%d",&m,&x1,&y1,&x2,&y2);
        for(int i=1;i<=n;++i){
            scanf("%d%d",&l[i].a.x,&l[i].b.x);
            l[i].a.y=y1,l[i].b.y=y2;
        }
        sort(l+1,l+n+1,cmp);
        for(int i=1;i<=m;++i){
            pot s;
            scanf("%d%d",&s.x,&s.y);
            ++cnt[search(s)];
        }
        puts("Box");
        for(int i=0;i<=n;++i)++tot[cnt[i]];
        for(int i=1;i<=m;++i)if(tot[i])printf("%d: %d\n",i,tot[i]);
    }
    return 0;
}

2018.07.04 POJ 2398 Toy Storage(二分+简单计算几何)的更多相关文章

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

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

  2. POJ 2398 Toy Storage 二分+叉积

    Description Mom and dad have a problem: their child, Reza, never puts his toys away when he is finis ...

  3. 2018.07.03 POJ 2653 Pick-up sticks(简单计算几何)

    Pick-up sticks Time Limit: 3000MS Memory Limit: 65536K Description Stan has n sticks of various leng ...

  4. poj 2398 Toy Storage(计算几何)

    题目传送门:poj 2398 Toy Storage 题目大意:一个长方形的箱子,里面有一些隔板,每一个隔板都可以纵切这个箱子.隔板将这个箱子分成了一些隔间.向其中扔一些玩具,每个玩具有一个坐标,求有 ...

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

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

  6. POJ 2398 - Toy Storage 点与直线位置关系

    Toy Storage Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5439   Accepted: 3234 Descr ...

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

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

  8. POJ 2398 Toy Storage(计算几何,叉积判断点和线段的关系)

    Toy Storage Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3146   Accepted: 1798 Descr ...

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

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

随机推荐

  1. 任务调度的方式:Timer、ScheduledExecutorService、spring task、quartz、XXL-JOB、Elastic-Job

    任务调度 定时任务调度:基于给定的时间点.给定的时间间隔.给定的执行次数自动执行的任务. Timer 介绍 Timer,简单无门槛,一般也没人用. Timer位于java.util包下,其内部包含且仅 ...

  2. static 和 global

    global global关键字如果用在function内部,则说明这个function内用的这个变量是全局的,全局变量就是在整个页面里都能起作用.例如 $conf = 1; function con ...

  3. 切换svn登录账户

    右键-->TortoiseSVN-->设置 找到:点击已缓存数据 在认证数据一栏点击:清空

  4. 在eclipse中创建maven项目,亲测有效,详细步骤

    一.想要使用maven,首先要配置本地maven的环境 1.在http://maven.apache.org/download.cgi中去下载maven 2. 3.下载完毕后将压缩包解压到自己记住的位 ...

  5. 如何在idea中导入本地所需要的jar包

    今天遇到一个问题,在idea创建普通java工程时不知道如何导入jar包,上网差了一下,也算是一个整理.

  6. SecureCRT结合xmanager远程启动图形化界面程序

    我们很多操作都是可以通过命令行的形式来完成,但是由于不支持图形模式,在一些需要图形界面的时候就很麻烦.本次设置可以在secureCRT中直接使用netca\dbca命令,通过xmanager的pass ...

  7. Pandas缺失数据处理

    Pandas缺失数据处理 Pandas用np.nan代表缺失数据 reindex() 可以修改 索引,会返回一个数据的副本: df1 = df.reindex(index=dates[0:4], co ...

  8. padding-top和margin-top的区别

    学习前端知识,对我们查找页面元素很有帮助,而且自己在原公司时,有参与一个QA系统,自己去设计了这个产品,出了原型图,同时设计了几个页面,希望通过做这个产品提高自己的技术,可是因为离职,所以计划搁浅了, ...

  9. 关于Python的OSError和IOError

    参考:http://stackoverflow.com/questions/29347790/difference-between-ioerror-and-oserror 在3.x版本已经移除,剩下O ...

  10. UVa 12100 Printer Queue(queue或者vector模拟队列)

    The only printer in the computer science students' union is experiencing an extremely heavy workload ...