Codeforces 581D Three Logos
2015-10-03 16:18
573 查看
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
output
input
output
非常好玩的图形模拟判断题,由于保证了是正方形,一开始就可以排除掉很多数据,然后边长也是固定的,接下去就把所有3种矩形所有可能的排布都试一遍,矩形首先自身可以换方向,故友2^3次,矩形排布互相可以换位置,故友3*2=6种,矩形排的样式共有4种分别为:
111 1 11 1
11 1 1
1
根据这些样式把对应的长宽数据对应进去,因为一开始限制了面积因素和边长,如果一个样式能够在竖边长和横边长都符合正确边长,就一定是正确的答案。具体细节请参考我的代码自己斟酌。
代码:
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
非常好玩的图形模拟判断题,由于保证了是正方形,一开始就可以排除掉很多数据,然后边长也是固定的,接下去就把所有3种矩形所有可能的排布都试一遍,矩形首先自身可以换方向,故友2^3次,矩形排布互相可以换位置,故友3*2=6种,矩形排的样式共有4种分别为:
111 1 11 1
11 1 1
1
根据这些样式把对应的长宽数据对应进去,因为一开始限制了面积因素和边长,如果一个样式能够在竖边长和横边长都符合正确边长,就一定是正确的答案。具体细节请参考我的代码自己斟酌。
代码:
#include<iostream> #include<cstdio> #include<cstdlib> #include<ctime> #include<string> #include<cstring> #include<algorithm> #include<fstream> #include<queue> #include<stack> #include<vector> #include<cmath> #include<iomanip> #define rep(i,n) for(i=1;i<=n;i++) #define MM(a,t) memset(a,t,sizeof(a)) #define INF 1e9 typedef long long ll; #define mod 1000000007 using namespace std; class rec{ public: int l,w; }a[100]; int n,xx; int f[300][5][5]; int res[500][500]; class point{ public: int x,y; }se[10][5]; void fun(int nn,int ii,int jj,int kk){ n++; f [se[nn][1].x][se[nn][1].y]=ii; f [se[nn][2].x][se[nn][2].y]=jj; f [se[nn][3].x][se[nn][3].y]=kk; } void setup(){ int i,j,k,nn; n=0; se[1][1].x=1; se[1][1].y=1; se[1][2].x=2; se[1][2].y=1; se[1][3].x=3; se[1][3].y=1; se[2][1].x=1; se[2][1].y=1; se[2][2].x=2; se[2][2].y=1; se[2][3].x=2; se[2][3].y=2; se[3][1].x=1; se[3][1].y=1; se[3][2].x=1; se[3][2].y=2; se[3][3].x=2; se[3][3].y=1; se[4][1].x=1; se[4][1].y=1; se[4][2].x=1; se[4][2].y=2; se[4][3].x=1; se[4][3].y=3; rep(nn,4) for(i=1;i<=4;i+=3) for(j=2;j<=5;j+=3) for(k=3;k<=6;k+=3){ fun(nn,i,j,k); fun(nn,i,k,j); fun(nn,j,i,k); fun(nn,j,k,i); fun(nn,k,i,j); fun(nn,k,j,i); } } bool cal(int ii){ int l=0,w=0; int i,j; rep(i,3){ if(a[f[ii][i][1]].l==0) continue; w=0; rep(j,3){ w+=a[f[ii][i][j]].w; } l+=a[f[ii][i][1]].l; if(w!=xx) return false; } if(l!=xx) return false; return true; } void pp(int x,int y,int ii){ int i,j; for(i=x+1;i<=x+a[ii].l;i++) for(j=y+1;j<=y+a[ii].w;j++) res[i][j]=ii; } void prt(int ii){ int i,j; int l=0,w; rep(i,3){ w=0; rep(j,3){ if(f[ii][i][j]==0) break; pp(l,w,f[ii][i][j]); w+=a[f[ii][i][j]].w; } l+=a[f[ii][i][1]].l; } printf("%d\n",xx); rep(i,xx){ rep(j,xx){ if(res[i][j]==1 || res[i][j]==4) printf("A"); else if(res[i][j]==2 || res[i][j]==5) printf("B"); else printf("C"); } printf("\n"); } } int main(){ int i,j; int sum; bool ff; setup(); while(1){ sum=0; MM(res,0); MM(a,0); rep(i,3){ scanf("%d%d",&a[i].l,&a[i].w); a[i+3].l=a[i].w; a[i+3].w=a[i].l; sum+=a[i].l*a[i].w; } xx=sqrt(sum+0.1); if(xx*xx!=sum){ printf("-1\n"); break; }ff=false; rep(i,n) if(cal(i)){ prt(i); ff=true; break; } if(!ff) printf("-1\n"); break; } return 0; }
相关文章推荐
- MacOs下安装go lang
- hdoj 1847 Good Luck in CET-4 Everybody! 【规律题】
- 教你如何在电脑上最快速简单的下载googleplay里面的APK
- Django后台整合TinyMCE富文本编辑器
- Go语言内存分配机制
- golang snmp开发学习笔记(一)
- golang的采集库
- hdu1056 HangOver
- 2011 Regular Polygon
- BZOJ1574 USACO 2009 Jan Gold 1.Earthquake Damage Solution
- GOF 23设计模式之 享元模式(FlyWeight)
- GO RPC
- 7-v4l2——format negotiation 格式协商
- GOF 23设计模式之 外观模式 迪米特法则
- BA-siemens-desigo_cc安装
- Alpha-expansion and Alpha-beta-swap Algorithm Flow
- hdu acm 4341 Gold miner
- Go-简洁的并发
- hihocoder#1044状态压缩dp+滚动数组
- HDOJ 1902 The Dragon of Loowater【贪心】