• codeforces #322 div 2 D. Three Logos (枚举)


    D. Three Logos
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Three companies decided to order a billboard with pictures of their logos. A billboard is a big square board. A logo of each company is a rectangle of a non-zero area.

    Advertisers will put up the ad only if it is possible to place all three logos on the billboard so that they do not overlap and the billboard has no empty space left. When you put a logo on the billboard, you should rotate it so that the sides were parallel to the sides of the billboard.

    Your task is to determine if it is possible to put the logos of all the three companies on some square billboard without breaking any of the described rules.

    Input

    The first line of the input contains six positive integers x1, y1, x2, y2, x3, y3 (1 ≤ x1, y1, x2, y2, x3, y3 ≤ 100), where xi and yi determine the length and width of the logo of the i-th company respectively.

    Output

    If it is impossible to place all the three logos on a square shield, print a single integer "-1" (without the quotes).

    If it is possible, print in the first line the length of a side of square n, where you can place all the three logos. Each of the next n lines should contain n uppercase English letters "A", "B" or "C". The sets of the same letters should form solid rectangles, provided that:

    • the sizes of the rectangle composed from letters "A" should be equal to the sizes of the logo of the first company,
    • the sizes of the rectangle composed from letters "B" should be equal to the sizes of the logo of the second company,
    • the sizes of the rectangle composed from letters "C" should be equal to the sizes of the logo of the third company,

    Note that the logos of the companies can be rotated for printing on the billboard. The billboard mustn't have any empty space. If a square billboard can be filled with the logos in multiple ways, you are allowed to print any of them.

    See the samples to better understand the statement.

    Sample test(s)
    input
    5 1 2 5 5 2
    output
    5
    AAAAA
    BBBBB
    BBBBB
    CCCCC
    CCCCC
    input
    4 4 2 6 4 2
    output
    6
    BBBBBB
    BBBBBB
    AAAACC
    AAAACC
    AAAACC
    AAAACC

    题意很清楚.
    给三个矩形,问能否拼成一个正方形.
    我们先把矩形都躺着放(保证x<=y)
    然后容易知道,一共有两种可能的方法
    一种是三个矩形罗在一起
    另外一种是一个矩形在上面,下面两个矩形竖着放.
    后一种方法又因为上面的矩形的不同以及下面两个矩形的横竖放置不同(00 01 10 11)*3
    所以一共有12种要枚举...
    直接写会累死...
    想了个简单点的办法,具体见代码.
    一遍AC,好爽!!!
      1 /*************************************************************************
      2     > File Name: code/cf/#322/D.cpp
      3     > Author: 111qqz
      4     > Email: rkz2013@126.com 
      5     > Created Time: 2015年09月30日 星期三 17时21分24秒
      6  ************************************************************************/
      7 #include<iostream>
      8 #include<iomanip>
      9 #include<cstdio>
     10 #include<algorithm>
     11 #include<cmath>
     12 #include<cstring>
     13 #include<string>
     14 #include<map>
     15 #include<set>
     16 #include<queue>
     17 #include<vector>
     18 #include<stack>
     19 #include<cctype>
     20 #define y1 hust111qqz
     21 #define yn hez111qqz
     22 #define j1 cute111qqz
     23 #define ms(a,x) memset(a,x,sizeof(a))
     24 #define lr dying111qqz
     25 using namespace std;
     26 #define For(i, n) for (int i=0;i<int(n);++i)  
     27 typedef long long LL;
     28 typedef double DB;
     29 const int inf = 0x3f3f3f3f;
     30 int ans;
     31 struct Point
     32 {
     33     int x,y;
     34 }p[10];
     35 char maze[110][110];
     36 int ss;
     37 int lst;
     38 int a[10],b[10];
     39 bool solve()
     40 {
     41     if (lst==-1) return false;
     42  //   cout<<"lst:"<<lst<<endl;
     43     if (p[0].x+p[1].x+p[2].x==p[0].y&&p[0].y==p[1].y&&p[0].y==p[2].y)
     44     {
     45     ans = p[0].y;
     46     for ( int i = 0 ; i < p[0].x ; i++)
     47     {
     48         for ( int j = 0 ; j < ans ; j++)
     49         {
     50         maze[i][j] = 'A';
     51         }
     52     }
     53     for ( int i = p[0].x ; i < p[0].x+p[1].x;i++)
     54     {
     55         for ( int j = 0 ; j < ans ; j++)
     56         {
     57         maze[i][j] = 'B';
     58         }
     59     }
     60     for ( int i = p[0].x + p[1].x ; i < ans ; i++)
     61     {
     62         for ( int j = 0 ; j < ans ; j++)
     63         {
     64         maze[i][j] = 'C';
     65         }
     66     }
     67     return true;
     68     }
     69 
     70     if (p[a[lst]].x+p[b[lst]].x==p[lst].y&&p[a[lst]].y==p[b[lst]].y&&p[a[lst]].y+p[lst].x==p[lst].y)
     71     {
     72     ans = p[lst].y;
     73     for ( int i = 0 ; i < p[lst].x ; i++)
     74     {
     75         for ( int j =  0  ;  j < ans ; j++)
     76         {
     77         maze[i][j] = char(lst+'A');
     78         }
     79     }
     80     for ( int i = p[lst].x ; i < ans ; i++)
     81     {
     82         for ( int j = 0  ;  j < ans  ;j++)
     83         {
     84         if (j<p[a[lst]].x)
     85         {
     86             maze[i][j]=char(a[lst]+'A');
     87            // cout<<i<<" "<<j<<" "<<char(a[lst]+'A')<<endl;
     88         }
     89         else
     90         {
     91             maze[i][j] = char (b[lst] + 'A');
     92         }
     93         }
     94     }
     95     return true;
     96     }
     97 
     98     
     99     if (p[a[lst]].x+ p[b[lst]].y==p[lst].y&&p[a[lst]].y==p[b[lst]].x&&p[a[lst]].y+p[lst].x==p[lst].y)
    100     {
    101     //cout<<"22222222222222222"<<endl;
    102     ans = p[lst].y;
    103     for ( int i = 0 ; i < p[lst].x ; i++)
    104     {
    105         for ( int j = 0 ;  j < ans ; j ++)
    106         {
    107         maze[i][j] = char(lst+'A');
    108         }
    109     }
    110     
    111     for ( int i = p[lst].x ; i < ans ; i++)
    112     {
    113         for ( int j = 0 ; j < ans ; j++)
    114         {
    115         if (j<p[a[lst]].x)
    116         {
    117             maze[i][j] =char(a[lst]+'A');
    118         }
    119         else
    120         {
    121             maze[i][j] = char(b[lst]+'A');
    122         }
    123         }
    124     }
    125     return true;
    126     }
    127 if (p[a[lst]].y+p[b[lst]].x==p[lst].y&&p[a[lst]].x==p[b[lst]].y&&p[a[lst]].x+p[lst].x==p[lst].y)
    128     {
    129     //cout<<"3333333333333333333333"<<endl;
    130     ans = p[lst].y;
    131     for ( int i = 0 ; i < p[lst].x ; i++)
    132     {
    133         for ( int j =  0  ;  j < ans ; j++)
    134         {
    135         maze[i][j] = char(lst+'A');
    136         }
    137     }
    138     for ( int i = p[lst].x ; i < ans ; i++)
    139     {
    140         for ( int j = 0  ;  j < ans  ;j++)
    141         {
    142         if (j<p[a[lst]].y)
    143         {
    144             maze[i][j]=char(a[lst]+'A');
    145         }
    146         else
    147         {
    148             maze[i][j] = char (b[lst] + 'A');
    149         }
    150         }
    151     }
    152     return true;
    153     }
    154 if (p[a[lst]].y+p[b[lst]].y==p[lst].y&&p[a[lst]].x==p[b[lst]].x&&p[a[lst]].x+p[lst].x==p[lst].y)
    155     {
    156     //    cout<<"44444444444444444444444444"<<endl;
    157     ans = p[lst].y;
    158     for ( int i = 0 ; i < p[lst].x ; i++)
    159     {
    160         for ( int j =  0  ;  j < ans ; j++)
    161         {
    162         maze[i][j] = char(lst+'A');
    163         }
    164     }
    165     for ( int i = p[lst].x ; i < ans ; i++)
    166     {
    167         for ( int j = 0  ;  j < ans  ;j++)
    168         {
    169         if (j<p[a[lst]].y)
    170         {
    171             maze[i][j]=char(a[lst]+'A');
    172          //   cout<<"haaa"<<a[lst]+'A'<<endl;
    173         }
    174         else
    175         {
    176             maze[i][j] = char (b[lst] + 'A');
    177         }
    178         }
    179     }
    180     return true;
    181     }
    182     return false;
    183 }
    184 int main()
    185 {
    186   #ifndef  ONLINE_JUDGE 
    187    freopen("in.txt","r",stdin);
    188   #endif
    189 
    190    ss = 0;
    191    lst = -1;
    192    a[0]=1;b[0]=2;
    193    a[1]=0;b[1]=2;
    194    a[2]=0;b[2]=1;
    195    for ( int i = 0 ; i < 3 ; i++) 
    196     {
    197     scanf("%d %d",&p[i].x,&p[i].y);
    198     if (p[i].x>p[i].y) swap(p[i].x,p[i].y);
    199     ss += p[i].x*p[i].y;
    200     }
    201     for ( int i = 0 ; i < 3 ; i++)
    202     {
    203     if (p[i].y*p[i].y==ss)
    204     {
    205         lst = i;
    206     }
    207     }
    208     if (solve())
    209     {
    210     printf("%d
    ",ans);
    211     for ( int i = 0 ; i < ans ; i++)
    212     {
    213         for ( int j = 0 ; j < ans ;  j++)
    214         {
    215         printf("%c",maze[i][j]);
    216         }
    217         printf("
    ");
    218     }
    219     }
    220     else
    221     {
    222     puts("-1");
    223     }
    224  #ifndef ONLINE_JUDGE  
    225   
    226     fclose(stdin);
    227   #endif
    228     return 0;
    229 }
    View Code
  • 相关阅读:
    Vue 组件之间传值(父子组件传值,vuex传值)
    利用computed和watch实现监听Vuex状态监听
    ESlint+VSCode自动格式化
    MySQL之分组查询(DQL)
    MySQL之排序查询(DQL)
    MySQL之条件查询(DQL)
    MySQL之概述
    jQuery之轮播图
    jQuery之添加删除记录
    jQuery之爱好选择
  • 原文地址:https://www.cnblogs.com/111qqz/p/4850592.html
Copyright © 2020-2023  润新知