Building a Stair
Time Limit: 3 Sec Memory Limit: 512 Mb
题目链接http://acm.csu.edu.cn:20080/csuoj/problemset/problem?pid=2309
Description
Little Barney just got a new toy cube set from his parents. His set contains n identical cubes. Barney immediately started building various objects with these cubes.
The latest thing Barney built is a stair. A stair consists of one or more towers of cubes, where the heights of towers are non-increasing from left to right. In the following picture, you can see three different shapes with 12 cubes each. The first two are stairs and the third one is not a stair.
Barney noticed that for some stairs you can turn your head 90 degrees to the right and you will see the same stair, but reversed! He calls such stairs symmetric. For example, the first stair above is symmetric, but the second one is not. Formally, a stair is symmetric if and only if when you reflect the picture over the x = y line, you get the same stair (where the x-axis is horizontal and oriented to the right, and the y-axis is vertical and oriented upwards).
Input
The single line of the input contains an integer n — the number of cubes at Barney’s disposal (1 ≤ n ≤ 100).
Output
If there is no symmetric stair with n cubes, output a single integer −1.
Otherwise, in the first line, output one integer m — the number of rows and columns in the picture of the stair (1 ≤ m ≤ 100). Then, output m lines describing the stair. Each line must contain exactly m characters ‘o’ (a lowercase English letter) or ‘.’, where ‘o’ describes a cell with a cube, and ‘.’ describes an empty cell. There must be exactly n ‘o’ characters in total. The cell in the bottom left corner must contain a cube. If there is more than one solution, output any of them.
Sample Input
3
Sample Output
3
…
o…
oo.
emmm,题目大意:给你木块的个数,让你打造一个台阶其右边的高度不超过左边,且台阶对称。用‘o’代表木块,‘.’代表空余部分。
这题其实很简单,从看题到写完估计10分钟就差不多了。。。
我们可以直接构造一个L形的阶梯就行了奇数刚刚好,偶数的话简单处理一下就OK了
以下是AC代码:
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
scanf ("%d",&n);
if (n==2){
printf ("-1\n");
return 0;
}
if (n%2==0){
n/=2;
printf ("%d\n",n);
for (int i=1; i<n-1; i++){
printf ("o");
for (int j=2; j<=n; j++){
printf (".");
}
printf ("\n");
}
printf ("oo");
for (int i=3; i<=n; i++) printf (".");
printf ("\n");
for (int i=1; i<=n; i++) printf ("o");
printf ("\n");
}
else {
n/=2;
printf ("%d\n",n+1);
for (int i=1; i<=n; i++){
printf ("o");
for (int j=2; j<=n+1; j++){
printf (".");
}
printf ("\n");
}
for (int i=1; i<=n+1; i++) printf ("o");
printf ("\n");
}
return 0;
}