zoukankan      html  css  js  c++  java
  • Shaping Regions(dfs)

     Shaping Regions

    Time Limit: 1 Sec  Memory Limit: 128 MB
    Submit: 124  Solved: 39
    [Submit][Status][Web Board]

    Description

    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.

    Input

    This problem includes multiple cases. The first line of input is a integer T represents the number of cases. 
    For each case: 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.

    Output

    For each case, output corresponding results separately.
    The output of each case 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 Input

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

    Sample Output

    1 91
    2 84
    3 187
    4 38

    HINT

    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).

    在矩形中涂色覆盖问每种颜色最后有多少块

    #include <iostream>
    #include <stdio.h>
    #include <string.h>
    #include <stack>
    #include <queue>
    #include <map>
    #include <set>
    #include <vector>
    #include <math.h>
    #include <algorithm>
    using namespace std;
    #define ls 2*i
    #define rs 2*i+1
    #define up(i,x,y) for(i=x;i<=y;i++)
    #define down(i,x,y) for(i=x;i>=y;i--)
    #define mem(a,x) memset(a,x,sizeof(a))
    #define w(a) while(a)
    #define LL long long
    const double pi = acos(-1.0);
    #define Len 200005
    #define mod 19999997
    const int INF = 0x3f3f3f3f;
    #define exp 1e-6
    int seq[1001][5];
    int col[1001],col_num[2501];
    int A,B;
    int n;
    long long dfs(int begin,int a,int b,int c,int d)
    {
        if(a >= c || b >= d) return 0;
        for(int i = begin; i <= n; i++)
        {
            int x1=seq[i][1],y1=seq[i][2],x2=seq[i][3],y2=seq[i][4];
            if(! (a>=x2 || b>=y2 || c<=x1 || d<=y1) )
            {
                if(a < x1 && c > x1)
                {
                    return dfs(i, a, b, x1, d)+dfs(i, x1, b, c, d);
                }
                else if(a < x2 && c > x2)
                {
                    return dfs(i, a, b,x2, d) + dfs(i,x2, b, c, d);
                }
                else
                    return dfs(i, a, b, c, y1) + dfs(i, a,y2, c, d);
            }
        }
        return ((c - a) * (d - b));
    }
    int main()
    {
        int t;
        scanf("%d",&t);
        while (t--)
        {
            scanf("%d%d%d",&A,&B,&n);
            seq[0][1] = seq[0][2] = 0;
            seq[0][3] = A,seq[0][4] =B,col[0] = 1;
            for(int i = 1; i <= n; i++)
            {
                scanf("%d%d%d%d%d",&seq[i][1],&seq[i][2],&seq[i][3],&seq[i][4],&col[i]);
            }
            memset(col_num, 0 ,sizeof(col_num));
            for(int i = n; i >= 0; i--)
            {
                col_num[col[i]] += dfs(i+1,seq[i][1],seq[i][2],seq[i][3],seq[i][4]);
            }
            for(int i = 1; i <= 2500; i++)
            {
                if(col_num[i] > 0)
                printf("%d %d
    ",i,col_num[i]);
            }
     
        }
        return 0;
     
    }
     
    /**************************************************************
        Problem: 1589
        User: aking2015
        Language: C++
        Result: Accepted
        Time:16 ms
        Memory:1516 kb
    ****************************************************************/
  • 相关阅读:
    Surface Mount Package Details
    Boost Converter
    IPC low/medium/high density 什么意思?
    SMT Surface Mount Technology footprint references
    Time Step Too Small in Multisim
    mOByDiC E90C2600 EOBD/OBDII to RS232 gateway
    STN1110 Multiprotocol OBD to UART Interpreter
    STN1170 Multiprotocol OBD to UART Interpreter
    BR16F84 OBD II Interface Chip For PWM, VPW, and ISO 9141-2 Vehicles
    ELM327 OBD to RS232 Interpreters
  • 原文地址:https://www.cnblogs.com/yuyixingkong/p/4471221.html
Copyright © 2011-2022 走看看