zoukankan      html  css  js  c++  java
  • USACO 6.2 Shaping Regions

    Shaping Regions

    N opaque rectangles (1 <= N <= 1000) of various colors are placed on a white sheet of paper whose size is A wide by B long. The rectangles are put with their sides parallel to the sheet's borders. All rectangles fall within the borders of the sheet so that different figures of different colors will be seen.

    The coordinate system has its origin (0,0) at the sheet's lower left corner with axes parallel to the sheet's borders.

    PROGRAM NAME: rect1

    INPUT FORMAT

    The order of the input lines dictates the order of laying down the rectangles. The first input line is a rectangle "on the bottom".

    Line 1: A, B, and N, space separated (1 <= A,B <= 10,000)
    Lines 2-N+1: Five integers: llx, lly, urx, ury, color: the lower left coordinates and upper right coordinates of the rectangle whose color is `color' (1 <= color <= 2500) to be placed on the white sheet. The color 1 is the same color of white as the sheet upon which the rectangles are placed.

    SAMPLE INPUT (file rect1.in)

    20 20 3
    2 2 18 18 2
    0 8 19 19 3
    8 0 10 19 4
    

    INPUT EXPLANATION

    Note that the rectangle delineated by 0,0 and 2,2 is two units wide and two high. Here's a schematic diagram of the input:

    11111111111111111111
    33333333443333333331
    33333333443333333331
    33333333443333333331
    33333333443333333331
    33333333443333333331
    33333333443333333331
    33333333443333333331
    33333333443333333331
    33333333443333333331
    33333333443333333331
    33333333443333333331
    11222222442222222211
    11222222442222222211
    11222222442222222211
    11222222442222222211
    11222222442222222211
    11222222442222222211
    11111111441111111111
    11111111441111111111
    

    The '4's at 8,0 to 10,19 are only two wide, not three (i.e., the grid contains a 4 at 8,0 and a 4 at 8,1 but NOT a 4 at 8,2 since this diagram can't capture what would be shown on graph paper).

    OUTPUT FORMAT

    The output file should contain a list of all the colors that can be seen along with the total area of each color that can be seen (even if the regions of color are disjoint), ordered by increasing color. Do not display colors with no area.

    SAMPLE OUTPUT (file rect1.out)

    1 91
    2 84
    3 187
    4 38

    ————————————————————————————————————————————题解
    和前面那个窗口题有什么区别……???
     1 /*
     2 ID: ivorysi
     3 LANG: C++
     4 PROG: rect1
     5 */
     6 #include <iostream>
     7 #include <cstdio>
     8 #include <cstring>
     9 #include <queue>
    10 #include <set>
    11 #include <vector>
    12 #include <algorithm>
    13 #define siji(i,x,y) for(int i=(x);i<=(y);++i)
    14 #define gongzi(j,x,y) for(int j=(x);j>=(y);--j)
    15 #define xiaosiji(i,x,y) for(int i=(x);i<(y);++i)
    16 #define sigongzi(j,x,y) for(int j=(x);j>(y);--j)
    17 #define inf 0x5f5f5f5f
    18 #define ivorysi
    19 #define mo 97797977
    20 #define hash 974711
    21 #define base 47
    22 #define fi first
    23 #define se second
    24 #define pii pair<int,int>
    25 #define esp 1e-8
    26 typedef long long ll;
    27 using namespace std;
    28 int n,col[10005],an[2505];
    29 struct data {
    30     int lx,ly,rx,ry;
    31 }squ[10005];
    32 int areas(data &t) {
    33     return (t.rx-t.lx+1)*(t.ry-t.ly+1);
    34 }
    35 void init() {
    36     scanf("%d%d%d",&squ[0].rx,&squ[0].ry,&n);
    37     --squ[0].rx;--squ[0].ry;
    38     siji(i,1,n) {
    39         scanf("%d%d%d%d",&squ[i].lx,&squ[i].ly,&squ[i].rx,&squ[i].ry);
    40         --squ[i].rx;
    41         --squ[i].ry;
    42         scanf("%d",&col[i]);
    43     }
    44     col[0]=1;
    45 }
    46 int dfs(int k,data q) {
    47     if(q.rx<q.lx || q.ry<q.ly) return 0;
    48     
    49 
    50     int ans=0;
    51     while((q.lx>squ[k].rx || q.rx<squ[k].lx || q.ly>squ[k].ry || q.ry<squ[k].ly )&&k<=n) ++k;
    52     if(k>n) return areas(q);
    53     if(q.lx<squ[k].lx) 
    54         ans+=dfs(k+1,(data){q.lx,max(q.ly,squ[k].ly),squ[k].lx-1,min(squ[k].ry,q.ry)});
    55     if(q.rx>squ[k].rx) 
    56         ans+=dfs(k+1,(data){squ[k].rx+1,max(q.ly,squ[k].ly),q.rx,min(squ[k].ry,q.ry)});
    57     if(q.ly<squ[k].ly) 
    58         ans+=dfs(k+1,(data){q.lx,q.ly,q.rx,squ[k].ly-1});
    59     if(q.ry>squ[k].ry) 
    60         ans+=dfs(k+1,(data){q.lx,squ[k].ry+1,q.rx,q.ry});
    61     return ans;
    62 }
    63 void solve() {
    64     init();
    65     siji(i,0,n) 
    66         an[col[i]]+=dfs(i+1,squ[i]);
    67     siji(i,1,2500) if(an[i]!=0) printf("%d %d
    ",i,an[i]);
    68 }
    69 int main(int argc, char const *argv[])
    70 {
    71 #ifdef ivorysi
    72     freopen("rect1.in","r",stdin);
    73     freopen("rect1.out","w",stdout);
    74 #else
    75     freopen("f1.in","r",stdin);
    76 #endif
    77     solve();
    78     return 0;
    79 }
     
  • 相关阅读:
    安卓学习39
    安卓学习38
    Python+Selenium学习--打印当前页面的title及url
    Python+Selenium学习--访问连接
    Python+Selenium学习--浏览器设置
    Python+Selenium学习--启动及关闭浏览器
    Go语言学习笔记(十八)之文件读写
    Go语言学习笔记(十七)之命令行参数
    Go语言学习笔记(十六)之格式化输入输出
    Go语言学习笔记(十五)之异常处理
  • 原文地址:https://www.cnblogs.com/ivorysi/p/6662387.html
Copyright © 2011-2022 走看看