Lusrica designs a mosquito coil in a board with n × n grids. The mosquito coil is a series of consecutive grids, each two neighboring grids of which share a common border. If two grids in the mosquito coil are not consecutive, they do not share any border, but they can share a common endpoint.

The mosquito coil Lusrica designed starts from the upper left corner of the board. It goes right to the last available grid. Alter the direction and go downward to the last available grid, and alter the direction again going left to the last available grid. To carry on after altering the direction and go upward to the last available grid. Then it goes right again and repeats the above turns.

It ends up in a grid such that the above process cannot be continued any more. Your mission now is to print the whole blueprint of Lusrica's mosquito coil.

Input

This problem has several test cases and the first line contains an integer t (1 ≤ t ≤ 36) which is the number of test cases. For each case a line contains an integer n (1 ≤ n ≤ 36) indicating the size of the board.

Output

For each case with input n, output n lines to describe the whole board. Each line contains n characters. If a grid is a part of Lusrica's mosquito coil, the corresponding character is '#', or ' ' (a single blank) if not.

样例输入复制

5
1
2
3
4
5

样例输出复制

#
##
#
###
#
###
####
#
# #
####
#####
#
### #
# #
#####

题目来源

ACM-ICPC 2017 Asia Qingdao

题意:给一个n,让你输出一个外圈长度为n的蚊香,蚊香都知道是啥样把!而且蚊香每一圈互相不能粘在一起。

题解:模拟,模拟之前一定要找规律,找到规律速度会快很多

1、第一行,第一列和最后一行是一定都要输出的

2、按顺序右、下、左、上四个方向走,如果按当前方向在继续往下走两步已经是#,换下一个方向走,走完n圈就结束

#include<iostream>
#include<string.h>
#include<string>
#include<algorithm>
#include<math.h>
#include<string>
#include<string.h>
#include<vector>
#include<utility>
#include<map>
#include<queue>
#include<set>
#define mx 0x3f3f3f3f
#define ll long long
using namespace std;
char s[][];
int main()
{
int n,t;
cin>>t;
while(t--)
{
cin>>n;
if(n==)
{
cout<<'#'<<endl;
continue;
}
if(n==)
{
cout<<"##"<<endl;
cout<<" #"<<endl;
continue;
}
if(n==)
{
cout<<"####"<<endl;
cout<<" #"<<endl;
cout<<"# #"<<endl;
cout<<"####"<<endl;
continue;
}
for(int i=;i<=n;i++)
{
for(int j=;j<=n;j++)
s[i][j]=' ';
}
for(int i=;i<=n;i++)//第一行、第n行,第n列一定都是#
{
s[][i]='#';
s[i][n]='#';
s[n][i]='#';
} int x=n,y=,temp=n;
while(temp--)
{
for(int i=x;i>=;i--)//向上
{
if(s[i-][y]=='#')
break;
s[i-][y]='#';
x--;
}
for(int i=y;i<=n;i++)//向右
{
if(s[x][i+]=='#')
break;
s[x][i+]='#';
y++;
}
for(int i=x;i<=n;i++)//向下
{
if(s[i+][y]=='#')
break;
s[i+][y]='#';
x++;
}
for(int i=y;i>=;i--)//向左
{
if(s[x][i-]=='#')
break;
s[x][i-]='#';
y--;
}
}
//这里要特别判断一下,因为当n为偶数的时候最后会多输出一个#
if(n%==)
s[x-][y+]=' ';
else if(n%==)
s[x][y]=' ';
///////////////////////////
for(int i=;i<=n;i++)
{
for(int j=;j<=n;j++)
cout<<s[i][j];
cout<<endl;
}
}
return ;
}

2017 青岛现场赛 I The Squared Mosquito Coil的更多相关文章

  1. 2017 青岛现场赛 Suffix

    Consider n given non-empty strings denoted by s1 , s2 , · · · , sn . Now for each of them, you need ...

  2. 2018ICPC青岛现场赛 重现训练

    先贴代码,以及简要题解. 和一个队友下午双排打了一下,队友光速签到,我签的J被嫌弃写得慢以及演员...然后我秒出了E了思路然而难以置信这么简单的思路当时才过了十几个,于是发现D.F不是太好做.最后交了 ...

  3. HDU 6212 Zuma 2017青岛网络赛 区间DP

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6212 解法:看了眼题就发现这个BZOJ 1032不是一毛一样?但是BZOJ上那是个巨坑,数据有错,原来 ...

  4. 2018 ACM-ICPC青岛现场赛 B题 Kawa Exam 题解 ZOJ 4059

    题意:BaoBao正在进行在线考试(都是选择题),每个题都有唯一的一个正确答案,但是考试系统有m个bug(就是有m个限制),每个bug表示为第u个问题和第v个问题你必须选择相同的选项,题目问你,如果你 ...

  5. 2018ACM/ICPC 青岛现场赛 E题 Plants vs. Zombies

    题意: 你的房子在0点,1,2,3,...,n(n<=1e5)点每个点都有一颗高度为0的花,浇一次水花会长a[i]. 你有一个机器人刚开始在你家,最多走m步,每一步只能往前走或者往后走,每走到一 ...

  6. 2018 ACM-ICPC 亚洲区域赛青岛现场赛 —— Problem F. Tournament

    题面:http://acm.zju.edu.cn/contest-materials/qd2018/qd2018_problems.pdf 题意: n个骑士决斗K轮 要求是每个骑士只能跟另外一个骑士决 ...

  7. 2017南宁现场赛E The Champion

    Bob is attending a chess competition. Now the competition is in the knockout phase. There are 2^r2r  ...

  8. 2017青岛网络赛1011 A Cubic number and A Cubic Number

    A Cubic number and A Cubic Number Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 65535/3276 ...

  9. 2017青岛网络赛1008 Chinese Zodiac

    Chinese Zodiac Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) T ...

随机推荐

  1. nodejs的forEach不支持break打断

  2. 吴裕雄--天生自然ORACLE数据库学习笔记:常用SQL*Plus命令

    set pause on set pause '按<enter>键继续' select user_id,username,account_status from dba_users; sh ...

  3. Spark教程——(9)Oozie编排Spark任务

    进入Hue管理界面,打开Oozie Editor: 将打包好的Spark程序上传到HDFS上,拖拽Spark任务,编辑任务属性,选择打包好的Spark程序,设置主函数所在类,设置选项参数: 保存为任务 ...

  4. 在这之后的两天又出现了w3wp进程找不到的情况了

    在这之后的两天又出现了w3wp进程找不到的情况了,我做了什么操作呢?无非就是vs中给一个过程附加删除了了一些dll,然后不停的重新生成解决方案,生成成功后,要调试,发现进程又没了. 实验了上面的方法, ...

  5. SpringMVC配置没有任何问题根据请求却怎么都找不到映射(tomcat所导致的问题)

    本人在做SpringMVC练习的时候,配置文件反复检查了不下十几遍,没有任何问题,然后就招了个之前的项目的源码复制进去,原来的项目没有任何问题,这个项目却怎么都不能跳转路径,然后有找了一个Spring ...

  6. underscore.js -2009年发布的js库

    2009 Underscore.js 0.1.0发布 Underscore一个JavaScript实用库,提供了一整套函数式编程的实用功能,但是没有扩展任何JavaScript内置对象.它是这个问题的 ...

  7. Python入门之元组

    一.什么是元祖 元祖是不可变类型(列表是可变类型) 为什么要设计元祖这样不可变类型?因为一旦创建了不可变类型的对象,对象内部的所有数据就不能被修改了,这样避免了 由于修改数据导致的错误.此外,对于不可 ...

  8. 120、Java中String类之实现首字母大写

    01.代码如下: package TIANPAN; /** * 此处为文档注释 * * @author 田攀 微信382477247 */ public class TestDemo { public ...

  9. ubutun18 install ibus-pinyin

    ref: https://www.cnblogs.com/asmer-stone/p/9069866.html Step1 $ sudo apt-get install ibus-pinyin

  10. 那些年我们踩过的坑,SQL 中的空值陷阱!

    文章目录 NULL 即是空 三值逻辑 空值比较 NOT IN 与空值 函数与空值 DISTINCT.GROUP BY.UNION 与空值 ORDER BY 与空值 空值处理函数 字段约束与空值 SQL ...