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. Update(stage3):第1节 redis组件:7、持久化

    7.redis的持久化 由于redis是一个内存数据库,所有的数据都是保存在内存当中的,内存当中的数据极易丢失,所以redis的数据持久化就显得尤为重要,在redis当中,提供了两种数据持久化的方式, ...

  2. jquery中 $(xxx).each() 和 $.each()的区别,以及enter键一键登录

    1.$().each 在dom处理上面用的较多.如果页面有多个input标签类型为text,对于这时用$().each来处理多个text,例如: $("input[type=’text’]& ...

  3. [运维] 如何访问虚拟机上的 Tomcat ?

    环境: 虚拟机: VMware 15 pro    操作系统  Linux  CentOS 7 64 物理机: Windows 7 事先准备: 1: 下载 Tomcat  的压缩包  apache-t ...

  4. java 操作 csv文件

    CSV是逗号分隔文件(Comma Separated Values)的首字母英文缩写,是一种用来存储数据的纯文本格式,通常用于电子表格或数据库软件.在 CSV文件中,数据“栏”以逗号分隔,可允许程序通 ...

  5. Android开发遇到的问题:不给include设置width、height,导致ListView GridView内容无法显示

    我的目的是做一个带有TextView的ListView列表页面. 以下是这个页面的xml: <?xml version="1.0" encoding="utf-8& ...

  6. PTA的Python练习题(一)

    最近宅家里没事干,顺便把python给学了.教程和书看了一段时间,但是缺少练习的平台. 想起大一时候练习C语言的PTA平台,就拿来练手了. (因为没有验证码无法提交题目,所以自己用pycharm来做题 ...

  7. keil中的一些技巧

    一  在Keil5中使用代码格式化工具Astyle(插件)https://blog.csdn.net/u010160335/article/details/78587411 二 将keil中的内存变量 ...

  8. Codeforces Round #586 (Div. 1 + Div. 2)E(拓扑排序,思维)

    #include<bits/stdc++.h>using namespace std;int n,m,s; vector<int>edge[200007];queue<i ...

  9. Atcoder Grand Contest 037C(贪心,优先队列,思维)

    #define HAVE_STRUCT_TIMESPEC//编译器中time.h和phread.h头文件中timespec结构体重名,故加此行#include<bits/stdc++.h> ...

  10. VUE引入模块之import xxx from 'xxx' 和 import {xxx} from 'xxx'的区别

    import FunName from ‘../xxx’ export defualt function FunName() { return fetch({ url: '/article/list' ...