POJ 2398 Toy Storage

蒻苣:弱弱很弱,路过的巨巨还不吝赐教!^.^...QAQ

题意:和2318好像啊。。。输出的是 盒子里面为0时,盒子里为t时,盒子的个数,1<=k<=n.

题解:sort一发。和2318唯一不同的是,这里的板是没有排序的。

注意:用long long 或者double ,int会WA的。还有就是注意Box大小写,冒号空格等等

代码

 1 #include<cstdio>
 2 #include<iostream>
 3 #include<cstring>
 4 #include<cmath>
 5 #include<algorithm>
 6 using namespace std;
 7 const double INF = 1E200;
 8 const double EP = 1E-10;
 9 const int MAXV = 300;
10 int sum[5000+50];
11 struct POINT{
12         int x,y;
13         POINT(int a = 0,int b = 0){x = a, y = b;}
14 };
15 POINT s[5000+50];
16 struct LINESEG{
17         POINT s;
18         POINT e;
19         LINESEG(POINT a,POINT b){s = a;e = b;}
20         LINESEG(){}
21 };
22 LINESEG t[5000+50];
23 int multiply(POINT sp,POINT ep,POINT op)
24 {
25         return ( ( sp.x - op.x ) * ( ep.y - op.y ) - ( ep.x - op.x ) * ( sp.y - op.y ) );
26 }
27 int cmp(LINESEG a,LINESEG b)
28 {
29         return a.e.x<=b.e.x;
30 }
31 int pos[5000+50];
32 int main() {
33     int n,m,x1,y1,x2,y2;
34     while(~scanf("%d",&n)&&n)
35     {
36             memset(sum,0,sizeof(sum));
37             memset(pos,0,sizeof(pos));
38             scanf("%d%d%d%d%d",&m,&x1,&y1,&x2,&y2);
39             int x,y;
40             for(int i = 1;i <= n;i++)
41             {
42                 scanf("%d%d",&t[i].e.x,&t[i].s.x);
43                 t[i].e.y = y1;
44                 t[i].s.y = y2;
45             }
46             sort(t+1,t+n+1,cmp);
47             for(int i = 0;i<m;i++) scanf("%d%d",&s[i].x,&s[i].y);
48             for(int i = 0;i<m;i++)
49             {
50                     int flag = 0;
51                     for(int j = 1;j<=n;j++)
52                     {
53                         if(multiply(t[j].e ,s[i] ,t[j].s ) >= 0)
54                         {
55                             flag = j;
56                             break;
57                         }
58                     }
59                     if(flag==0) sum[n+1]++;
60                     else sum[flag]++;
61             }
62             for(int i = 1;i <= n+1; i++)
63                    pos[sum[i]]++;
64             printf("Box\n");
65             for(int i = 1;i <= n+1; i++)
66             {
67                     if(pos[i])
68                     {
69                             printf("%d: %d\n",i,pos[i]);
70                     }
71             }
72     }
73     return 0;
74 }
View Code

 

posted on 2015-08-18 23:26  小松song  阅读(76)  评论(0)    收藏  举报

导航