zoukankan      html  css  js  c++  java
  • 3.1.4 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 and 8,0 and a 4 and 8,1 but NOT a 4 and 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
    

    HINTS (use them carefully!)

    /*
    ID: makeeca1
    PROG: rect1
    LANG: C++
    */
    #include<cstdio>
    #include<cmath>
    using namespace std;
    #define MAX 10010
    int rx[MAX],ry[MAX],lx[MAX],ly[MAX],s[MAX],color[MAX],max,n,tot,i;
    void cut(int x1,int y1,int x2,int y2,int t){
        while (t<=tot && (x1>=rx[t] || x2<=lx[t] || y1>=ry[t] || y2<=ly[t])) t++;
        if (t>tot) {s[color[i]]+=abs((x1-x2)*(y1-y2));return;}
        if (x1<=lx[t]){cut(x1,y1,lx[t],y2,t+1);x1=lx[t];}
        if (x2>=rx[t]){cut(rx[t],y1,x2,y2,t+1);x2=rx[t];}
        if (y1<=ly[t]){cut(x1,y1,x2,ly[t],t+1);y1=ly[t];}
        if (y2>=ry[t]){cut(x1,ry[t],x2,y2,t+1);y2=ry[t];}
    }
    int main(){
        freopen("rect1.in","r",stdin);
        freopen("rect1.out","w",stdout);
        scanf("%d%d%d",&rx[1],&ry[1],&n);
        lx[1]=0;ly[1]=0;color[1]=1;max=1;tot=n+1;
        for (i=1;i<=n;i++){
            scanf("%d%d%d%d%d",&lx[i+1],&ly[i+1],&rx[i+1],&ry[i+1],&color[i+1]);
            if (max<color[i+1])max=color[i+1];
        }
        for (i=n+1;i>=1;i--)
            cut(lx[i],ly[i],rx[i],ry[i],i+1);
        for (i=1;i<=max;i++)if (s[i])printf("%d %d
    ",i,s[i]);
        return 0;
    }
  • 相关阅读:
    C# Debugger.IsAttached 调试启动浏览器 VS if DEBUG 启动调试内容
    【转载】如何三个月从零基础到C#中级程序员
    【转载】如何成为一个高级程序员
    如何找回QQ聊天记录、语音、图片?
    hexo博客yili主题个性化自定义教程(1) ——借鉴中学习,初认yili主题
    2019hexo博客部署到coding该绕的坑-奥怪的小栈
    2019Hexo博客Next主题深度美化 打造一个炫酷博客(2)-奥怪的小栈
    2019软件工程专业大学排名附官网-奥怪的小栈
    浅谈互联网+足球
    2019基于Hexo快速搭建个人博客,打造一个炫酷博客(1)-奥怪的小栈
  • 原文地址:https://www.cnblogs.com/makeecat/p/3289267.html
Copyright © 2011-2022 走看看