码迷,mamicode.com
首页 > 其他好文 > 详细

poj 2398 Toy Storage

时间:2017-10-15 19:45:12      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:pre   code   images   head   没有   mission   sep   esc   rect   

Toy Storage
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 6094   Accepted: 3639

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

 
题意:这个题和2318的题意差不多,这个题只让你把有玩具的格子输出,然后按照排序输出就行了,但这个包括没有落在盒子里的玩具(好像包括,有点忘了,做的太久了)
 
题解:与poj 2318一样,按照题目意思进行模拟,仍然二分位置,找到压栈,然后排序输出
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <vector>
#include <string>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#define zero(a) fabs(a)<eps
#define max( x, y )  ( ((x) > (y)) ? (x) : (y) )
#define min( x, y )  ( ((x) < (y)) ? (x) : (y) )
#define lowbit(x) (x&(-x))
typedef long long ll;
const double pi=acos(-1.0);
const int inf=0x3f3f3f3f;
const ll linf=0x3f3f3f3f3f3f3f3f;
const int maxn = 5050;
const double eps=1e-8;
using namespace std;
struct point
{
    int x,y;
    point() {}
    point(int _x,int _y)
    {
        x = _x;
        y = _y;
    }
    point operator -(const point &b)const
    {
        return point(x - b.x,y - b.y);
    }
//叉积
    double operator ^(const point &b)const
    {
        return x*b.y - y*b.x;
    }
//点积
    double operator *(const point &b)const
    {
        return x*b.x + y*b.y;
    }
//绕原点旋转角度B(弧度值),后x,y的变化
    void transXY(double B)
    {
        double tx = x,ty = y;
        x = tx*cos(B) - ty*sin(B);
        y = tx*sin(B) + ty*cos(B);
    }
};
struct Line
{
    point s,e;
    Line() {}
    Line(point _s,point _e)
    {
        s = _s;
        e = _e;
    }
};
Line line[maxn];
//int ans[maxn];
struct qw
{
    int num,id;
} ans[maxn];

int xmult(point p0,point p1,point p2)
{
    return (p1-p0)^(p2-p0);
}

bool cmp1(Line a,Line b)
{
    return a.s.x < b.s.x;
}

int cmp(qw x,qw y)
{
    return x.num>y.num;
}

int main()
{
    int n,m,x1,y1,x2,y2;
    while(~scanf("%d",&n)&&n)
    {
        scanf("%d%d%d%d%d",&m,&x1,&y1,&x2,&y2);
        for(int i=0;i<n;i++){
            ans[i].id=i;
            ans[i].num=0;
        }
        int t1,t2;
        for(int i=0;i<n;i++){
            scanf("%d%d",&t1,&t2);
            line[i]=Line(point(t1,y1),point(t2,y2));
        }
        line[n]=Line(point(t2,y1),point(t2,y2));
        sort(line, line+n+1, cmp1);
//        printf("test \n");
        while(m--){
            int x,y;
            point p;
            int tmp;
            scanf("%d%d",&x,&y);
            p=point(x,y);
            int l=0,r=n;
            while(l<=r){
                int mid=(l+r)/2;
                if(xmult(p,line[mid].s,line[mid].e)<0){
                    tmp=mid;
                    r=mid-1;
                }
                else l=mid+1;
            }
            ans[tmp].num++;
        }
        sort(ans,ans+n,cmp);
        printf("Box\n");
        for(int i=0;i<n;i++){
            if(ans[i].num!=0){
                printf("%d: %d\n",ans[i].id,ans[i].num);
            }
        }
    }
    return 0;
}
/*
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
*/

 

poj 2398 Toy Storage

标签:pre   code   images   head   没有   mission   sep   esc   rect   

原文地址:http://www.cnblogs.com/lalalatianlalu/p/7672631.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!