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. Codeforces Global Round 6 - D. Decreasing Debts(思维)

    题意:有$n$个人,$m$个债务关系,$u_{i}$,$v_{i}$,$d_{i}$表示第$u_{i}个人$欠第$v_{i}$个人$d_{i}$块钱,现在你需要简化债务关系,使得债务总额最小.比如,$ ...

  2. linux(centos6.10)下去掉mysql的强密码验证

    vim /etc/my.cnf shift + G      光标移到最下方: o    进入插入模式,同时换行: 添加一行语句:  validate_password=OFF 保存退出. servi ...

  3. Codeforces Round #589 (Div. 2)E(组合数,容斥原理,更高复杂度做法为DP)

    #define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;int f[257],fac[257],ifa ...

  4. [理解] C++ 中的 源文件 和 头文件

    我是学 C井 的, 现在在工作中主要使用的编程语言是 Java, 还记得当初在第一次接触到 Cpp 的时候, 听到的第一个概念就是 Cpp 的头文件和源文件, 当初理解了好久, 死活都弄不明白, 现在 ...

  5. FFplay 命令

    1. 查看支持的格式: ffplay.exe -formats 2. 播放PCM裸流: ffplay.exe - -channels -f s16le -i pcm_file_path 根据PCM文件 ...

  6. 设计模式课程 设计模式精讲 3-3 开闭原则 coding

    1 课程讲解 1.1 开闭原则定义 1.2 不重要内容 2 代码coding 2.1 基类 2.2 需求:打印出原价和折扣后的价格.(接口不应该随意变化,面向接口编程) 1 课程讲解 1.1 开闭原则 ...

  7. 解决fastjson反序列化日期0000-00-00失败的方案

    解决fastjson反序列化日期0000-00-00失败的方案 22 Jul 2016 一.案例场景复原 示例场景里涉及两个class:TestDemo.java, DateBeanDemo.java ...

  8. AttributeError: 'Word2Vec' object has no attribute 'vocab'

    在 Gensim 1.0.0 版本后移除了 vocab,需使用 model.wv.vocab

  9. rc

    1,协同过滤. 2,协方差:用来衡量,他们的变化趋势是不是一致的. 3,皮尔逊相关系数:-1,负相关.1:正相关. 4,用皮尔逊相关系数来算相关性是最多的.

  10. KVM的客户机可以使用的存储

    KVM的虚拟机可以直接使用宿主机器内的存储设备,比如可以把宿主机器内的硬盘直接暴露给 虚拟机挂载使用 -hda /dev/sfa(宿主机的设备文件) 还可以把镜像文件挂接到虚拟机,作为虚拟机的存储设备 ...