pku 1262 input 离散化

pku 1262 input 离散化

题意:
给出一些瓷砖,以及需要铺的面积w*h(从(0,0)到(w,h)),求:
(1)这些瓷砖是否有重叠
(2)这些瓷砖是否超过了地面的边界
(3)这些瓷砖能否完整的铺盖地面
瓷砖个数n<100
解法:
对于第一问,传统的做法应该是离散化+线段树。但是此题数据量很小,n<100离散化后面积不过160000,可以暴力判重。
对于第二问,扫描一遍即可
对于第三问,计算下总面积即可。
代码:
 1  # include  < cstdio >
 2  using   namespace  std;
 3  # include  < vector >
 4  # include  < algorithm >
 5  # include  < cstring >
 6  int  data[ 101 ][ 4 ],c1,tmp1[ 500 ],c2,tmp2[ 500 ],n,w,h;
 7  bool  used[ 500 ][ 500 ];
 8  int  main()
 9  {
10       int  test;
11      scanf( " %d " , & test);
12       while (test -- )
13      {
14           int  total = 0 ;
15          scanf( " %d%d%d " , & w, & h, & n);
16          c1 = c2 = 0 ;
17          memset(used, 0 , sizeof (used));
18           for ( int  i = 0 ;i < n;i ++ )
19          {
20              scanf( " %d%d%d%d " , & data[i][ 0 ], & data[i][ 1 ], & data[i][ 2 ], & data[i][ 3 ]);
21              tmp1[c1 ++ ] = data[i][ 0 ];
22              tmp1[c1 ++ ] = data[i][ 2 ] - 1 ;
23              tmp2[c2 ++ ] = data[i][ 1 ];
24              tmp2[c2 ++ ] = data[i][ 3 ] - 1 ;
25          }
26          sort(tmp1,tmp1 + c1);
27          c1 = unique(tmp1,tmp1 + c1) - tmp1;
28          sort(tmp2,tmp2 + c2);
29          c2 = unique(tmp2,tmp2 + c2) - tmp2;
30           for ( int  i = 0 ;i < n;i ++ )
31          {
32               int  xl = lower_bound(tmp1,tmp1 + c1,data[i][ 0 ]) - tmp1,xh = lower_bound(tmp1,tmp1 + c1,data[i][ 2 ] - 1 ) - tmp1;
33               int  yl = lower_bound(tmp2,tmp2 + c2,data[i][ 1 ]) - tmp2,yh = lower_bound(tmp2,tmp2 + c2,data[i][ 3 ] - 1 ) - tmp2;
34               for ( int  j = xl;j <= xh;j ++ )
35                   for ( int  k = yl;k <= yh;k ++ )
36                       if (used[j][k])
37                      {
38                          printf( " NONDISJOINT\n " );
39                           goto  end;
40                      }
41                       else  used[j][k] = true ;
42          }
43           for ( int  i = 0 ;i < n;i ++ )
44               if (data[i][ 0 ] < 0 || data[i][ 0 ] > w || data[i][ 2 ] < 0 || data[i][ 2 ] > w || data[i][ 1 ] < 0 || data[i][ 1 ] > h || data[i][ 3 ] < 0 || data[i][ 3 ] > h)
45              {
46                  printf( " NONCONTAINED\n " );
47                   goto  end;
48              }
49           for ( int  i = 0 ;i < n;i ++ )
50              total += (data[i][ 2 ] - data[i][ 0 ]) * (data[i][ 3 ] - data[i][ 1 ]);
51           if (total != w * h) printf( " NONCOVERING\n " );
52           else  printf( " OK\n " );
53          end:;
54      }
55  }
56 

你可能感兴趣的:(pku 1262 input 离散化)