Three Logos

CodeForces - 581D

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 nuppercase 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
  1. 5 1 2 5 5 2
Output
  1. 5
    AAAAA
    BBBBB
    BBBBB
    CCCCC
    CCCCC
Input
  1. 4 4 2 6 4 2
Output
  1. 6
    BBBBBB
    BBBBBB
    AAAACC
    AAAACC
    AAAACC
    AAAACC
  2.  
  3. sol:只有三个标记当然可以暴力模拟,就是判-1略微蛋疼
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef int ll;
  4. inline ll read()
  5. {
  6. ll s=;
  7. bool f=;
  8. char ch=' ';
  9. while(!isdigit(ch))
  10. {
  11. f|=(ch=='-'); ch=getchar();
  12. }
  13. while(isdigit(ch))
  14. {
  15. s=(s<<)+(s<<)+(ch^); ch=getchar();
  16. }
  17. return (f)?(-s):(s);
  18. }
  19. #define R(x) x=read()
  20. inline void write(ll x)
  21. {
  22. if(x<)
  23. {
  24. putchar('-'); x=-x;
  25. }
  26. if(x<)
  27. {
  28. putchar(x+''); return;
  29. }
  30. write(x/);
  31. putchar((x%)+'');
  32. return;
  33. }
  34. #define W(x) write(x),putchar(' ')
  35. #define Wl(x) write(x),putchar('\n')
  36. const int N=;
  37. int n=,n1,n2,n3,m1,m2,m3;
  38. char Map[N][N];
  39. inline void OutPut()
  40. {
  41. Wl(n);
  42. int i,j;
  43. for(i=;i<=n;i++)
  44. {
  45. for(j=;j<=n;j++) putchar(Map[i][j]);
  46. putchar('\n');
  47. }
  48. }
  49. #define NO {puts("-1"); exit(0);}
  50. inline void Judge()
  51. {
  52. if(n*n!=(n1*m1+n2*m2+n3*m3)) NO
  53. if(n1==n&&n2==n&&n3==n) if(m1+m2+m3!=n) NO
  54. int i,j,c1=,c2=,c3=;
  55. for(i=;i<=n;i++)
  56. {
  57. for(j=;j<=n;j++)
  58. {
  59. if(Map[i][j]=='A') c1++;
  60. else if(Map[i][j]=='B') c2++;
  61. else if(Map[i][j]=='C') c3++;
  62. }
  63. }
  64. if((c1!=n1*m1)||(c2!=n2*m2)||(c3!=n3*m3)) NO
  65. }
  66. int main()
  67. {
  68. int i,j,Lastn,Lastm;
  69. R(n1); R(m1); R(n2); R(m2); R(n3); R(m3);
  70. if(n1<m1) swap(n1,m1); if(n2<m2) swap(n2,m2); if(n3<m3) swap(n3,m3);
  71. n=max(n1,max(m1,max(n2,max(m2,max(n3,m3)))));
  72. memset(Map,' ',sizeof Map);
  73. if(n1==n)
  74. {
  75. for(i=;i<=n1;i++) for(j=;j<=m1;j++) Map[i][j]='A';
  76. if(n2==n)
  77. {
  78. for(i=;i<=n;i++) for(j=m1+;j<=m1+m2;j++) Map[i][j]='B';
  79. }
  80. else
  81. {
  82. if(n2+m1==n) swap(n2,m2);
  83. for(i=;i<=n2;i++) for(j=m1+;j<=n;j++) Map[i][j]='B';
  84. }
  85. for(i=;i<=n;i++)
  86. {
  87. for(j=;j<=n;j++)
  88. {
  89. if(!isupper(Map[i][j])) Map[i][j]='C';
  90. }
  91. }
  92. }
  93. else if(n2==n)
  94. {
  95. for(i=;i<=n2;i++) for(j=;j<=m2;j++) Map[i][j]='B';
  96. if(n1==n)
  97. {
  98. for(i=;i<=n;i++) for(j=m2+;j<=m2+m1;j++) Map[i][j]='A';
  99. }
  100. else
  101. {
  102. if(n1+m2==n) swap(n1,m1);
  103. for(i=;i<=n1;i++) for(j=m2+;j<=n;j++) Map[i][j]='A';
  104. }
  105. for(i=;i<=n;i++)
  106. {
  107. for(j=;j<=n;j++)
  108. {
  109. if(!isupper(Map[i][j])) Map[i][j]='C';
  110. }
  111. }
  112. }
  113. else
  114. {
  115. for(i=;i<=n3;i++) for(j=;j<=m3;j++) Map[i][j]='C';
  116. if(n1==n)
  117. {
  118. for(i=;i<=n;i++) for(j=m3+;j<=m3+m1;j++) Map[i][j]='A';
  119. }
  120. else
  121. {
  122. if(n1+m3==n) swap(n1,m1);
  123. for(i=;i<=n1;i++) for(j=m3+;j<=n;j++) Map[i][j]='A';
  124. }
  125. for(i=;i<=n;i++)
  126. {
  127. for(j=;j<=n;j++)
  128. {
  129. if(!isupper(Map[i][j])) Map[i][j]='B';
  130. }
  131. }
  132. }
  133. Judge();
  134. OutPut();
  135. return ;
  136. }
  137. /*
  138. Input
  139. 5 1 5 2 5 2
  140. Output
  141. 5
  142. AAAAA
  143. BBBBB
  144. BBBBB
  145. CCCCC
  146. CCCCC
  147.  
  148. Input
  149. 4 4 2 6 4 2
  150. Output
  151. 6
  152. BBBBBB
  153. BBBBBB
  154. AAAACC
  155. AAAACC
  156. AAAACC
  157. AAAACC
  158.  
  159. input
  160. 100 100 100 100 100 100
  161. output
  162. -1
  163. */
  1.  

codeforces581D的更多相关文章

随机推荐

  1. Tomcat 对 HTTP 协议的实现(下)

    在<Tomcat 对 HTTP 协议的实现(上)>一文中,对请求的解析进行了分析,接下来对 Tomcat 生成响应的设计和实现继续分析.本文首发于(微信公众号:顿悟源码) 一般 Servl ...

  2. ADO.NET学习(一)

    一.ADO.NET简介 ADO.NET可以看作是C#语言访问数据库的一种方式.编程语言编写的程序需要数据库的支持,那么怎样才能让他们建立连接呢?当然是ADO.NET 二.ADO.NET 整体流程 1) ...

  3. 简述在ADO中使用接口的抽象数据提供程序以及ADO.NET数据提供程序工厂模型

    如何在ADO中使用接口的抽象数据提供程序 在cofig中 appSettings下,配置数据连接类型 <appSettings> <!--这个键值映射到枚举值中的某个值--> ...

  4. dubbo-源码分析Consumer

    counsumer使用服务的时候会在xml中配置<dubbo:reference> dubbo在spring.handles里的NamespaceHandle又有如下配置: registe ...

  5. 【译】.NET Core 3.0 中的新变化

    .NET Core 3.0 是 .NET Core 平台的下一主要版本.本文回顾了 .Net Core 发展历史,并展示了它是如何从基本支持 Web 和数据工作负载的版本 1,发展成为能够运行 Web ...

  6. Yii2设计模式——注册树模式

    应用举例 在Yii.php中: <?php class ServiceLocator extends Component { //保存实例化的对象,每个对象都是单例,且有唯一string类型的I ...

  7. 20190421-那些年使用过的CSS预处理器(CSS Preprocessor)之Sass and Less

    写在前面乱七八糟的前言: emmm,还是决定把Sass与Less单独出来写成一篇,可能会稍微好辣么一丢丢?TAT语法特性是真的香,通篇下来能吸收个10%自我感觉已经很nice了,毕竟渣渣的我有渣渣的自 ...

  8. MySQL字段操作与数据处理

    一,对字段的操作 1.拼接字段:Concat()函数 多数DBMS使用 + 或者 || 来实现拼接,而MySQL使用 Concat() 函数来实现拼接. 实例: Concat()函数拼接时加上的字符需 ...

  9. webpack4.x笔记-配置基本的前端开发环境(一)

    webpack的基本使用 webpack 本质上是一个打包工具,它会根据代码的内容解析模块依赖,帮助我们把多个模块的代码打包.借用 webpack 官网的图片: 虽然webpack4.x的版本可以零配 ...

  10. HTML5之webSocket使用

    webSocket是什么 webSocket是HTML5新出的一种协议,底层是基于TCP/IP协议的.跟http没有关系,只是复用了http握手通道,用来升级协议. webSocket的作用 轮询:客 ...