atcoder Grid Components(构造)

要你构造一个指定联通块数量的黑白图,具体构造方案类似一个一层一层的塔,可以跑一遍程序看.有一些细节要处理,没什么意思.

#include 
#include 
#include 
#include 
using namespace std;
#define debug(x) std::cerr << #x << " = " << (x) << std::endl
typedef long long LL;
const int MAXN = 2e5+17;
char mp[100][100];
int main(int argc ,char const *argv[])
{
    #ifdef noob
    freopen("Input.txt","r",stdin);freopen("Output.txt","w",stdout);
    #endif  
    int n,m;
    cin>>n>>m;
    int dap = 0;
    int k1 = ceil(1.0*n/50),k2;
    if(n>1) m-=1;
    k2 = k2=ceil(1.0*m/50);
    if(m>0) n--;
    k1 = ceil(1.0*n/50);
    while(k1--) 
    {
        n-=50;
        for (int i = 0; i < 100; ++i)
        {
            for (int j = 0; j < 3; ++j)
            {
                int tj= j+dap*3;
                if(((tj-1)%3==0)&&i&1) mp[i][tj]='.';
                else mp[i][tj]='#';
            }
        }
        if(n<0)
        {
            int tms = -1*n;
            for (int i = 0; i < 100; ++i)
            {
                for (int j = 0; j < 3; ++j)
                {
                    int tj=j+dap*3;
                    if(mp[i][tj]=='.'&&tms>0) 
                    {
                        mp[i][tj] = '#'; 
                        tms--;
                    }
                }
            }
            dap++;
            break;
        }
        dap++;
    }
    while(k2--) 
    {
        m-=50;
        for (int i = 0; i < 100; ++i)
        {
            for (int j = 0; j < 3; ++j)
            {
                int tj= j+dap*3;
                if(((tj-1)%3==0)&&i&1) mp[i][tj]='#';
                else mp[i][tj]='.';
            }
        }
        if(m<0)
        {
            int tms = -1*m;
            for (int i = 0; i < 100; ++i)
            {
                for (int j = 0; j < 3; ++j)
                {
                    int tj=j+dap*3;
                    if(mp[i][tj]=='#'&&tms>0) 
                    {
                        mp[i][tj] = '.'; 
                        tms--;
                    }
                }
            }
            dap++;
            break;
        }
        dap++;
    }
    cout<<100<<" "<3<for (int i = 0; i < 100; ++i)
        cout<return 0;   
}

你可能感兴趣的:(atcoder Grid Components(构造))