hdu 6665 Calabash and Landlord (2019 Multi-University Training Contest 8 1009) (discrete)

Topic link: http: //acm.hdu.edu.cn/showproblem.php pid = 6665?

Title effect: four points are given left and right corners of the two rectangles, two rectangular coordinate axes parallel to the coordinate plane Q (including negative axis, but only in the first quadrant of the rectangle, the edge portion may be positive axis) is divided into several two rectangular areas (intent to ask several communication set point but because it is a real number corresponding to the point Q is the region).

Ideas: such as title, discrete. You can see the value of point coordinates can be very large, but note that seek only the number of regions, but not with the number of points required in each area, so the information we want only the positional relationship between the point and the point of this when easiest way is to enumerate the relationship between each point, but this was too tired (yes lazy is the source of human progress), roughly two dozen count, even if there are some cases overlap all columns must again before it is too much trouble (confident). This time is necessary to use discrete, as previously said, we just positional relationship between the points and points, then we can not change them relatively free to change the size of the value in, which means you can put a lot of value then down to a small range. . . You can then painted the violence.

The specific operation is, first of all the x, y values ​​in the sort together, then small to large assignment, I chose scratch Fu even value, thus avoiding some point in real time can not be applied to cause coloring region statistics is not the case (corresponding to the increased distance between the line and the line), then reordering, arranged in the reading order, and to each edge marked directly labeled, then the coloring can dfs.

code show as below:

#include<iostream>
#include<cstdio>
#include<set>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<vector>
#include<stdlib.h>
#include<queue>
#include<algorithm>
#include<map>
#include<stack>
using namespace std;
int co[20][20];
struct node
{
    int v;
    int id;
} is[20 is ];
 int CC;
 BOOL CMP (Node A, Node B) 
{ 
    return AV < BV; 
} 
BOOL cmpid (Node A, Node B) 
{ 
    return a.id < b.id; 
} 
int cHEC ( int X, int Y ) // check whether the bounds or has been painted 
{ 
    iF (X> = 20 is || Y> = 20 is || X < 0 || Y < 0 || CO.'s [X] [Y]! = 0 ) 
    { 
        return  0 ; 
    } 
    return  . 1 ; 
} 
int mi The [ . 4][2]= {0,-1,0,1,1,0,-1,0};
int dfs(int x,int y,int cc)
{
    co[x][y]=cc;
    for(int i=0; i<4; i++)
    {
        if(chec(x+mi[i][0],y+mi[i][1]))
        {
            dfs(x+mi[i][0],y+mi[i][1],cc);
        }
    }
    return 0;
}
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        memset(co,0,sizeof(co));
        for(int i=0; i<8; i++)
        {
            scanf("%d",&e[i].v);
            e[i].id=i;
        }
        Sort (E, E + . 8 , CMP); // Sort the discrete
         int K = 2 ;
         int BE = E [ 0 ] .v; 
        E [ 0 ] .v = 2 ;
         for ( int I = . 1 ; I < . 8 ; I ++ ) // discrete phase assignment 
        { 
            IF (E [I] .v == BE) 
            { 
                E [I] .v = K; 
            } 
            the else 
            { 
                BE = E [I] .v; 
                K + = 2 ;
                E [I] .v = K; 
            } 
        } 
        Sort (E, E + . 8 , cmpid); // row back to the original order
         for ( int I = 0 ; I < . 8 ; I + = . 4 ) // marker segment 
        { 
            for ( int J = E [I] .v; J <= E [I + 2 ] .v; J ++ ) 
            { 
                CO.'s [J] [E [I + . 1 ] .v] = - . 1 ; 
                CO.'s [J] [E [I + . 3 ] .v] = - . 1 ; 
            } 
            for ( int j=e[i+1].v; j<=e[i+3].v; j++)
            {
                co[e[i].v][j]=-1;
                co[e[i+2].v][j]=-1;
            }
        }
        cc=0;
        for(int i=0; i<20; i++)//涂色
        {
            for(int j=0; j<20; j++)
            {
                if(co[i][j]==0)
                {
                    dfs(i,j,++cc);
                }
                //printf("%2d ",co[i][j]);
            }
        }
        printf("%d\n",cc);
    }
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/forever3329/p/11367630.html