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

Toy Storage

时间:2017-07-15 19:51:49      阅读:166      评论:0      收藏:0      [点我收藏+]

标签:dad   each   etc   eps   ebe   next   tchar   get   number   

Toy Storage
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
可以说,这是“TOYS”一题的2.0版本。这次题意变成了:求出放了1个,2个,3个。。。物品的箱子有几个。那么只是所求变了,其他都没变。
技术分享
 1 #include<cmath>
 2 #include<cstring>
 3 #include<cstdio>
 4 #include<algorithm>
 5 #define LL long long
 6 using namespace std;
 7 struct data{
 8     int U,D;
 9     bool operator < (const data &u) const {return U<u.U;}
10 }A[10005];
11 int n,m,ans[10005],ret[10005];
12 int uy,dy;
13 int read(){
14     int x=0,f=1; char ch=getchar();
15     while (ch<0||ch>9){if (ch==-) f=-f; ch=getchar();}
16     while (ch>=0&&ch<=9) x=x*10+ch-0,ch=getchar();
17     return x*f;
18 }
19 int cross(int x_0,int y_0,int x_1,int y_1){
20     return x_0*y_1-x_1*y_0;
21 }
22 int main(){
23     for (n=read(); n; n=read()){
24         puts("Box");
25         m=read(),A[0].U=A[0].D=read(),uy=read(),A[n+1].U=A[n+1].D=read(),dy=read();
26         for (int i=1; i<=n; i++) A[i].U=read(),A[i].D=read();
27         sort(A+1,A+1+n);
28         memset(ans,0,sizeof ans);
29         memset(ret,0,sizeof ret);
30         for (int i=1; i<=m; i++){
31             int x=read(),y=read();
32             int L=1,R=n+1,mid,pos;
33             while (L<=R){
34                 mid=(L+R)>>1;
35                 if (cross(A[mid].U-A[mid].D,uy-dy,x-A[mid].D,y-dy)>0)
36                 R=mid-1,pos=mid; else L=mid+1;
37             }
38             ans[pos-1]++;
39         }
40         for (int i=0; i<=n; i++) ret[ans[i]]++;
41         for (int i=1; i<=m; i++) if (ret[i]>0) printf("%d: %d\n",i,ret[i]);
42     }
43     return 0;
44 } 
View Code

 

Toy Storage

标签:dad   each   etc   eps   ebe   next   tchar   get   number   

原文地址:http://www.cnblogs.com/whc200305/p/7183762.html

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