2017 青岛现场赛 I The Squared Mosquito Coil
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
样例输出复制
#
##
#
###
#
###
####
#
# #
####
#####
#
### #
# #
#####
题目来源
题意:给一个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的更多相关文章
- 2017 青岛现场赛 Suffix
Consider n given non-empty strings denoted by s1 , s2 , · · · , sn . Now for each of them, you need ...
- 2018ICPC青岛现场赛 重现训练
先贴代码,以及简要题解. 和一个队友下午双排打了一下,队友光速签到,我签的J被嫌弃写得慢以及演员...然后我秒出了E了思路然而难以置信这么简单的思路当时才过了十几个,于是发现D.F不是太好做.最后交了 ...
- HDU 6212 Zuma 2017青岛网络赛 区间DP
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6212 解法:看了眼题就发现这个BZOJ 1032不是一毛一样?但是BZOJ上那是个巨坑,数据有错,原来 ...
- 2018 ACM-ICPC青岛现场赛 B题 Kawa Exam 题解 ZOJ 4059
题意:BaoBao正在进行在线考试(都是选择题),每个题都有唯一的一个正确答案,但是考试系统有m个bug(就是有m个限制),每个bug表示为第u个问题和第v个问题你必须选择相同的选项,题目问你,如果你 ...
- 2018ACM/ICPC 青岛现场赛 E题 Plants vs. Zombies
题意: 你的房子在0点,1,2,3,...,n(n<=1e5)点每个点都有一颗高度为0的花,浇一次水花会长a[i]. 你有一个机器人刚开始在你家,最多走m步,每一步只能往前走或者往后走,每走到一 ...
- 2018 ACM-ICPC 亚洲区域赛青岛现场赛 —— Problem F. Tournament
题面:http://acm.zju.edu.cn/contest-materials/qd2018/qd2018_problems.pdf 题意: n个骑士决斗K轮 要求是每个骑士只能跟另外一个骑士决 ...
- 2017南宁现场赛E The Champion
Bob is attending a chess competition. Now the competition is in the knockout phase. There are 2^r2r ...
- 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 ...
- 2017青岛网络赛1008 Chinese Zodiac
Chinese Zodiac Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) T ...
随机推荐
- linux和windows系统的区别
在21世纪的今天,互联网可以说是当代发展最为迅速的行业,举个很简单的例子,现在的我们不论什么年龄阶层,几乎人手都有一部手机,上面的某博,某音,末手等软件,更是受到多数人的热爱,并且人们不仅仅用其来消遣 ...
- 【译】索引进阶(十七): SQL SERVER索引最佳实践
[译注:此文为翻译,由于本人水平所限,疏漏在所难免,欢迎探讨指正] 原文链接:传送门. 在本章我们给出一些建议:贯穿本系列我们提取出了十四条基本指南,这些基本的指南将会帮助你为你的数据库创建最佳的索引 ...
- php 高级 提高PHP代码的性能10条建议
1.echo比print要快很多.两个方法都会在页面上打印东西,不过echo不返回任何值,print会在成功或失败的时候返回0或1. 2.include_once比include更加耗时.因为它需要去 ...
- Plastic Bottle Manufacturer - What Is The Direction Of Plastic Bottles?
Plastic bottle manufacturers explain: protective packaging for cosmetic cleaning products requires b ...
- 在javaweb中对于session的使用
1.初次调用session时: String username="student"; HttpSession session=request.getSession(true);// ...
- 什么是 SDK?
通俗而言: 1.其实很简单,SDK 就是 Software Development Kit 的缩写,中问意思是: 软件开发工具包. 2.这是一个覆盖面相当广泛的名词,可以这么说: 辅助开发某一类软件的 ...
- 【代码总结】GD库中图片缩印
bool imagecopyresampled ( resource $dst_image, resource $src_image, int $dst_x, int $dst_y, int $src ...
- PAT T1014 Circles of Friends
大水题,dfs判连通块的数量,bfs每个点找朋友圈的最大直径~ #include<bits/stdc++.h> using namespace std; ; vector<int&g ...
- PAT T1005 Programming Pattern
建立后缀数组,遍历height数组找到连续大于len的最长子序列~ #include<bits/stdc++.h> using namespace std; ; char s[maxn]; ...
- MySQL之innodb和myisam的区别
innodb和myisam的区别: MyISAM在磁盘上存储成三个文件.第一个文件的名字以表的名字开始,扩展名指出文件类型, .frm文件存储表定义, 数据文件的扩展名为.MYD, 索引文件的扩展名是 ...