解题报告 之 CodeForces 581D Three Logos
Description
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 Input
5 1 2 5 5 2
5 AAAAA BBBBB BBBBB CCCCC CCCCC
4 4 2 6 4 2
6 BBBBBB BBBBBB AAAACC AAAACC AAAACC AAAACC
Source
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<cmath>
using namespace std;
typedef long long ll;
struct Rec
{
int l, w;
char ch;
bool operator <( const Rec& rhs )const
{
return l < rhs.l;
}
int sq()
{
return l*w;
}
};
Rec rec[4];
int main()
{
while(scanf( "%d%d%d%d%d%d", &rec[1].l, &rec[1].w, &rec[2].l, &rec[2].w, &rec[3].l, &rec[3].w ) == 6)
{
for(int i = 1; i <= 3; i++)
{
if(rec[i].l < rec[i].w)swap( rec[i].l, rec[i].w );
rec[i].ch = 'A' - 1 + i;
}
sort( rec + 1, rec + 4 );
int len = rec[3].l;
if((rec[3].l*rec[3].l) != (rec[1].sq() + rec[2].sq() + rec[3].sq()))
{
printf( "-1\n" );
continue;
}
printf( "%d\n", len );
for(int i = 1; i <= rec[3].w; i++)
{
for(int j = 1; j <= rec[3].l; j++)
{
printf( "%c", rec[3].ch );
}
printf( "\n" );
}
if(rec[2].l!=len&&rec[3].w + rec[2].w != len) swap( rec[2].l, rec[2].w );
for(int i = 1; i <= rec[2].w; i++)
{
for(int j = 1; j <= rec[2].l; j++)
{
printf( "%c", rec[2].ch );
}
for(int j = 1; j <= len - rec[2].l; j++)
{
printf( "%c", rec[1].ch );
}
printf( "\n" );
}
for(int i = 1; i <=len-rec[3].w- rec[2].w; i++)
{
for(int j = 1; j <= len; j++)
{
printf( "%c", rec[1].ch );
}
printf( "\n" );
}
}
return 0;
}
首先再次赞叹队友叔叔的高智商。另外第一次感到做CF的乐趣在于一定要保持头脑的清晰,就会发现其实都不难。