codeforces 581d

題意:問三個矩形能不能組成一個正方形


思路:其實就只有題目給的那2種情況,枚舉每個放的情況和順序就好了


#include<cstring>
#include<cstdlib>
#include<iostream>
#include<stdio.h>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
#define N 2000010
#define lim 200000
#define MOD 1000000007
#define M 1000000006
#define LL long long

struct Logos
{
    int w;
    int h;

    int id;
};

Logos l[3];
Logos h[3];
int v[3];

bool judge()
{
    if(l[0].w==l[1].w)
    {
        if(l[1].w==l[2].w&&l[0].h+l[1].h+l[2].h==l[0].w)
        {
            printf("%d\n",l[0].w);
            for(int k=0;k<3;k++)
            {
               for(int i=0;i<l[k].h;i++)
               {
                   for(int j=0;j<l[k].w;j++)
                   {
                       printf("%c",'A'+l[k].id);
                   }
                   printf("\n");
               }
            }
            return true;
        }
        else if(l[0].h+l[1].h==l[2].h&&l[0].w+l[2].w==l[2].h)
        {
            printf("%d\n",l[2].h);
            for(int j=0;j<l[2].h;j++)
            {
                for(int i=0;i<l[0].w+l[2].w;i++)
                {
                    if(i>=l[0].w)
                        printf("%c",'A'+l[2].id);
                    else if(j<l[0].h)
                        printf("%c",'A'+l[0].id);
                    else
                        printf("%c",'A'+l[1].id);
                }
                printf("\n");
            }
            return true;
        }
    }
    return false;
}

bool dfs(int x)
{
    if(x==3)
    {
        return judge();
    }
    for(int i=0;i<3;i++)
    {
        if(v[i])continue;
        v[i]=1;
        l[x]=h[i];
        if(dfs(x+1))return true;
        swap(l[x].h,l[x].w);
        if(dfs(x+1))return true;
        swap(l[x].h,l[x].w);
        v[i]=0;
    }
    return false;
}


int main()
{
    for(int i=0;i<3;i++){
        scanf("%d%d",&h[i].w,&h[i].h);
        h[i].id=i;
    }
    if(!dfs(0))
        printf("-1");
    return 0;
}



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章