B. Building a Stair---简单构造

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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值