zoukankan      html  css  js  c++  java
  • CF581D Three Logos 暴力

    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.

    Examples
    Input
    Copy
    5 1 2 5 5 2
    Output
    Copy
    5
    AAAAA
    BBBBB
    BBBBB
    CCCCC
    CCCCC
    Input
    Copy
    4 4 2 6 4 2
    Output
    Copy
    6
    BBBBBB
    BBBBBB
    AAAACC
    AAAACC
    AAAACC
    AAAACC
    暴力就完事了;
    代码应该是看不下去的;
    #include<iostream>
    #include<cstdio>
    #include<algorithm>
    #include<cstdlib>
    #include<cstring>
    #include<string>
    #include<cmath>
    #include<map>
    #include<set>
    #include<vector>
    #include<queue>
    #include<bitset>
    #include<ctime>
    #include<deque>
    #include<stack>
    #include<functional>
    #include<sstream>
    //#include<cctype>
    //#pragma GCC optimize(2)
    using namespace std;
    #define maxn 1000005
    #define inf 0x7fffffff
    //#define INF 1e18
    #define rdint(x) scanf("%d",&x)
    #define rdllt(x) scanf("%lld",&x)
    #define rdult(x) scanf("%lu",&x)
    #define rdlf(x) scanf("%lf",&x)
    #define rdstr(x) scanf("%s",x)
    typedef long long  ll;
    typedef unsigned long long ull;
    typedef unsigned int U;
    #define ms(x) memset((x),0,sizeof(x))
    const long long int mod = 1e9 + 7;
    #define Mod 1000000000
    #define sq(x) (x)*(x)
    #define eps 1e-4
    typedef pair<int, int> pii;
    #define pi acos(-1.0)
    //const int N = 1005;
    #define REP(i,n) for(int i=0;i<(n);i++)
    typedef pair<int, int> pii;
    inline ll rd() {
    	ll x = 0;
    	char c = getchar();
    	bool f = false;
    	while (!isdigit(c)) {
    		if (c == '-') f = true;
    		c = getchar();
    	}
    	while (isdigit(c)) {
    		x = (x << 1) + (x << 3) + (c ^ 48);
    		c = getchar();
    	}
    	return f ? -x : x;
    }
    
    ll gcd(ll a, ll b) {
    	return b == 0 ? a : gcd(b, a%b);
    }
    int sqr(int x) { return x * x; }
    
    
    /*ll ans;
    ll exgcd(ll a, ll b, ll &x, ll &y) {
    	if (!b) {
    		x = 1; y = 0; return a;
    	}
    	ans = exgcd(b, a%b, x, y);
    	ll t = x; x = y; y = t - a / b * y;
    	return ans;
    }
    */
    
    int h[4], w[4];
    char mp[300][300];
    char ch[3] = { 'A','B','C' };
    int main() {
    	//ios::sync_with_stdio(0);
    	for (int i = 1; i <= 3; i++) {
    		cin >> h[i] >> w[i]; if (h[i] > w[i])swap(h[i], w[i]);
    	}
    	if ((w[1] == w[2]&&w[2] == w[3]) && h[1] + h[2] + h[3] == w[1]) {
    		cout << w[1] << endl;
    		for (int i = 1; i <= w[1]; i++) {
    			for (int j = 1; j <= h[1]; j++)mp[i][j] = 'A';
    		//	cout << endl;
    		}
    		for (int i = 1; i <= w[1]; i++) {
    			for (int j = h[1] + 1; j <= h[2] + h[1]; j++)mp[i][j] = 'B';
    		//	cout << endl;
    		}
    		for (int i = 1; i <= w[1]; i++) {
    			for (int j = 1 + h[1] + h[2]; j <= w[1]; j++)mp[i][j] = 'C';
    		//	cout << endl;
    		}
    		for (int i = 1; i <= w[1]; i++) {
    			for (int j = 1; j <= w[1]; j++)cout << mp[i][j];
    			cout << endl;
    		}
    		return 0;
    	}
    	else {
    		int pos = 0;
    		int maxx = 0;
    		for (int i = 1; i <= 3; i++) {
    			if (w[i] > maxx) {
    				maxx = w[i]; pos = i;
    			}
    		}
    		if (pos == 1) {
    			if (h[2] + h[3] == w[1]) {
    				if (w[3] == w[2] && w[2] + h[1] == w[1]) {
    					cout << w[1] << endl;
    					for (int i = 1; i <= w[1]; i++) {
    						for (int j = 1; j <= h[1]; j++)mp[i][j] = 'A';
    						//	cout << endl;
    					}
    					for (int i = 1; i <= h[2]; i++) {
    						for (int j = 1 + h[1]; j <= w[1]; j++)mp[i][j] = 'B';
    						//	cout << endl;
    					}
    					for (int i = 1 + h[2]; i <= w[1]; i++)
    						for (int j = 1 + h[1]; j <= w[1]; j++)mp[i][j] = 'C';
    					for (int i = 1; i <= w[1]; i++) {
    						for (int j = 1; j <= w[1]; j++)cout << mp[i][j];
    						cout << endl;
    					}
    					return 0;
    				}
    			}
    			else if (h[2] + w[3] == w[1]) {
    				if (w[2] == h[3] && w[2] + h[1] == w[1]) {
    					cout << w[1] << endl;
    					for (int i = 1; i <= w[1]; i++) {
    						for (int j = 1; j <= h[1]; j++)mp[i][j] = 'A';
    						//	cout << endl;
    					}
    					for (int i = 1; i <= h[2]; i++) {
    						for (int j = 1 + h[1]; j <= w[1]; j++)mp[i][j] = 'B';
    						//	cout << endl;
    					}
    					for (int i = 1 + h[2]; i <= w[1]; i++)
    						for (int j = 1 + h[1]; j <= w[1]; j++)mp[i][j] = 'C';
    					for (int i = 1; i <= w[1]; i++) {
    						for (int j = 1; j <= w[1]; j++)cout << mp[i][j];
    						cout << endl;
    					}
    					return 0;
    				}
    			}
    			else if (w[2] + h[3] == w[1]) {
    				if (h[2] == w[3] && h[2] + h[1] == w[1]) {
    					cout << w[1] << endl;
    					for (int i = 1; i <= w[1]; i++) {
    						for (int j = 1; j <= h[1]; j++)mp[i][j] = 'A';
    						//	cout << endl;
    					}
    					for (int i = 1; i <= w[2]; i++) {
    						for (int j = 1 + h[1]; j <= w[1]; j++)mp[i][j] = 'B';
    						//	cout << endl;
    					}
    					for (int i = 1 + w[2]; i <= w[1]; i++)
    						for (int j = 1 + h[1]; j <= w[1]; j++)mp[i][j] = 'C';
    					for (int i = 1; i <= w[1]; i++) {
    						for (int j = 1; j <= w[1]; j++)cout << mp[i][j];
    						cout << endl;
    					}
    					return 0;
    				}
    			}
    			else if (w[2] + w[3] == w[1]) {
    				if (h[2] == h[3] && h[2] + h[1] == w[1]) {
    					cout << w[1] << endl;
    					for (int i = 1; i <= w[1]; i++) {
    						for (int j = 1; j <= h[1]; j++)mp[i][j] = 'A';
    						//	cout << endl;
    					}
    					for (int i = 1; i <= w[2]; i++) {
    						for (int j = 1 + h[1]; j <= w[1]; j++)mp[i][j] = 'B';
    						//	cout << endl;
    					}
    					for (int i = 1 + w[2]; i <= w[1]; i++)
    						for (int j = 1 + h[1]; j <= w[1]; j++)mp[i][j] = 'C';
    					for (int i = 1; i <= w[1]; i++) {
    						for (int j = 1; j <= w[1]; j++)cout << mp[i][j];
    						cout << endl;
    					}
    					return 0;
    				}
    			}
    		}
    
    		else if (pos == 2) {
    			if (h[1] + h[3] == w[2]) {
    				if (w[3] == w[1] && w[1] + h[2] == w[2]) {
    					cout << w[2] << endl;
    					for (int i = 1; i <= w[2]; i++) {
    						for (int j = 1; j <= h[2]; j++)mp[i][j] = 'B';
    						//	cout << endl;
    					}
    					for (int i = 1; i <= h[1]; i++) {
    						for (int j = 1 + h[2]; j <= w[2]; j++)mp[i][j] = 'A';
    						//	cout << endl;
    					}
    					for (int i = 1 + h[1]; i <= w[2]; i++)
    						for (int j = 1 + h[2]; j <= w[2]; j++)mp[i][j] = 'C';
    					for (int i = 1; i <= w[2]; i++) {
    						for (int j = 1; j <= w[2]; j++)cout << mp[i][j];
    						cout << endl;
    					}
    					return 0;
    				}
    			}
    			if (h[1] + w[3] == w[2]) {
    				if (h[3] == w[1] && w[1] + h[2] == w[2]) {
    					cout << w[2] << endl;
    					for (int i = 1; i <= w[2]; i++) {
    						for (int j = 1; j <= h[2]; j++)mp[i][j] = 'B';
    						//	cout << endl;
    					}
    					for (int i = 1; i <= h[1]; i++) {
    						for (int j = 1 + h[2]; j <= w[2]; j++)mp[i][j] = 'A';
    						//	cout << endl;
    					}
    					for (int i = 1 + h[1]; i <= w[2]; i++)
    						for (int j = 1 + h[2]; j <= w[2]; j++)mp[i][j] = 'C';
    					for (int i = 1; i <= w[2]; i++) {
    						for (int j = 1; j <= w[2]; j++)cout << mp[i][j];
    						cout << endl;
    					}
    					return 0;
    				}
    			}
    			if (w[1] + h[3] == w[2]) {
    				if (w[3] == h[1] && h[1] + h[2] == w[2]) {
    					cout << w[2] << endl;
    					for (int i = 1; i <= w[2]; i++) {
    						for (int j = 1; j <= h[2]; j++)mp[i][j] = 'B';
    						//	cout << endl;
    					}
    					for (int i = 1; i <= w[1]; i++) {
    						for (int j = 1 + h[2]; j <= w[2]; j++)mp[i][j] = 'A';
    						//	cout << endl;
    					}
    					for (int i = 1 + w[1]; i <= w[2]; i++)
    						for (int j = 1 + h[2]; j <= w[2]; j++)mp[i][j] = 'C';
    					for (int i = 1; i <= w[2]; i++) {
    						for (int j = 1; j <= w[2]; j++)cout << mp[i][j];
    						cout << endl;
    					}
    					return 0;
    				}
    			}
    			if (w[1] + w[3] == w[2]) {
    				if (h[3] == h[1] && h[1] + h[2] == w[2]) {
    					cout << w[2] << endl;
    					for (int i = 1; i <= w[2]; i++) {
    						for (int j = 1; j <= h[2]; j++)mp[i][j] = 'B';
    						//	cout << endl;
    					}
    					for (int i = 1; i <= w[1]; i++) {
    						for (int j = 1 + h[2]; j <= w[2]; j++)mp[i][j] = 'A';
    						//	cout << endl;
    					}
    					for (int i = 1 + w[1]; i <= w[2]; i++)
    						for (int j = 1 + h[2]; j <= w[2]; j++)mp[i][j] = 'C';
    					for (int i = 1; i <= w[2]; i++) {
    						for (int j = 1; j <= w[2]; j++)cout << mp[i][j];
    						cout << endl;
    					}
    					return 0;
    				}
    			}
    		}
    		else {
    		if (h[1] + h[2] == w[3]) {
    			if (w[2] == w[1] && w[1] + h[3] == w[3]) {
    				cout << w[3] << endl;
    				for (int i = 1; i <= w[3]; i++) {
    					for (int j = 1; j <= h[3]; j++)mp[i][j] = 'C';
    					//	cout << endl;
    				}
    				for (int i = 1; i <= h[1]; i++) {
    					for (int j = 1 + h[3]; j <= w[3]; j++)mp[i][j] = 'A';
    					//	cout << endl;
    				}
    				for (int i = 1 + h[1]; i <= w[3]; i++)
    					for (int j = 1 + h[3]; j <= w[3]; j++)mp[i][j] = 'B';
    				for (int i = 1; i <= w[3]; i++) {
    					for (int j = 1; j <= w[3]; j++)cout << mp[i][j];
    					cout << endl;
    				}
    				return 0;
    			}
    		}
    		if (h[1] + w[2] == w[3]) {
    			if (h[2] == w[1] && w[1] + h[3] == w[3]) {
    				cout << w[3] << endl;
    				for (int i = 1; i <= w[3]; i++) {
    					for (int j = 1; j <= h[3]; j++)mp[i][j] = 'C';
    					//	cout << endl;
    				}
    				for (int i = 1; i <= h[1]; i++) {
    					for (int j = 1 + h[2]; j <= w[3]; j++)mp[i][j] = 'A';
    					//	cout << endl;
    				}
    				for (int i = 1 + h[1]; i <= w[3]; i++)
    					for (int j = 1 + h[3]; j <= w[3]; j++)mp[i][j] = 'B';
    				for (int i = 1; i <= w[3]; i++) {
    					for (int j = 1; j <= w[3]; j++)cout << mp[i][j];
    					cout << endl;
    				}
    				return 0;
    			}
    		}
    		if (w[1] + h[2] == w[3]) {
    			if (w[2] == h[1] && h[1] + h[3] == w[3]) {
    				cout << w[3] << endl;
    				for (int i = 1; i <= w[3]; i++) {
    					for (int j = 1; j <= h[3]; j++)mp[i][j] = 'C';
    					//	cout << endl;
    				}
    				for (int i = 1; i <= w[1]; i++) {
    					for (int j = 1 + h[3]; j <= w[3]; j++)mp[i][j] = 'A';
    					//	cout << endl;
    				}
    				for (int i = 1 + w[1]; i <= w[3]; i++)
    					for (int j = 1 + h[3]; j <= w[3]; j++)mp[i][j] = 'B';
    				for (int i = 1; i <= w[3]; i++) {
    					for (int j = 1; j <= w[3]; j++)cout << mp[i][j];
    					cout << endl;
    				}
    				return 0;
    			}
    		}
    		if (w[1] + w[2] == w[3]) {
    			if (h[2] == h[1] && h[1] + h[3] == w[3]) {
    				cout << w[3] << endl;
    				for (int i = 1; i <= w[3]; i++) {
    					for (int j = 1; j <= h[3]; j++)mp[i][j] = 'C';
    					//	cout << endl;
    				}
    				for (int i = 1; i <= w[1]; i++) {
    					for (int j = 1 + h[3]; j <= w[3]; j++)mp[i][j] = 'A';
    					//	cout << endl;
    				}
    				for (int i = 1 + w[1]; i <= w[3]; i++)
    					for (int j = 1 + h[3]; j <= w[3]; j++)mp[i][j] = 'B';
    				for (int i = 1; i <= w[3]; i++) {
    					for (int j = 1; j <= w[3]; j++)cout << mp[i][j];
    					cout << endl;
    				}
    				return 0;
    			}
    		}
    		}
    
    	}
    	cout << -1 << endl;
    	return 0;
    }
    
    
    
    EPFL - Fighting
  • 相关阅读:
    PGsql 基本用户权限操作
    Node.js版本管理工具 nvm
    js 数字前面自动补零
    浮点数向偶数舍入的问题 Round-to-Even for Floating Point
    Linux 目录下属性查看操作
    C语言之Bit-wise Operation和Logical Operation
    (转)SqlBulkCopy批量复制数据
    (转)VS2010启动调试时老是提示正在下载公共符号
    转 SVN 在vs中的使用
    (转)关于 HTTP meta 的 IE=edge 说明
  • 原文地址:https://www.cnblogs.com/zxyqzy/p/10293805.html
Copyright © 2011-2022 走看看