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 ...
随机推荐
- JAVA 通过POI 模版,导出excel
如有不足,欢迎指正,谢谢 ! 1.Maven引入 POI jar包.模版和结果文件.rar下载 <dependency> <groupId>org.apache.poi< ...
- 「Luogu P5080 Tweetuzki 爱序列」
题目大意 给出一些数,需要求出 \(\frac{a_{i+1}}{3}=a_i\) 或 \(a_{i+1}=2 \times a_i\) 时最长的序列 \(a\). 分析 可以发现符合条件的序列 \( ...
- [读书]The Man Who Solved the Market
出乎个人意料的是,西蒙斯是从FICC类品种起步的,包括量化投资方法获得第一次重大突破也是在FICC品种上. FICC市场的深度不够,所以文艺复兴科技实现规模扩张是股票策略成功之后的事情,很靠后. 虽然 ...
- php 安装 swoole
1.安装swoole cd /usr/local/src wget https://github.com/swoole/swoole-src/archive/v1.9.1-stable.tar.gz ...
- 《JavaScript高级程序设计》读书笔记(三)基本概念第一小节
内容---语法 本小节---数据类型 本小节 undefined,null,Boolean---流程控制语句---理解函数 任何语言的核心都必然会描述这门语言最基本的工作原理.而描述的内容通常都要涉及 ...
- Jquery+ajax模板
$.ajax({ url:'', type:'POST', //GET async:true, //或false,是否异步 data:{ name ...
- 一 Spring概述
知识点概要: 1 SpringIOC入门(XML).Spring的Bean管理.Spring属性注入 2 SpringIOC注解方式.Spring的AOP开发(XML) 3 Spring的AOP注解开 ...
- LeetCode 680. Valid Palindrome II(双指针)
题意:给定一个字符串,可以最多去掉一个字符,判断是否可以使该字符串成为一个回文串. 分析:head和tail双指针分别指向字符串首尾,如果s[head] != s[tail],则要么去掉s[head] ...
- 【PAT甲级】1014 Waiting in Line (30 分)(队列维护)
题面: 输入四个正整数N,M,K,Q(N<=20,M<=10,K,Q<=1000),N为银行窗口数量,M为黄线内最大人数,K为需要服务的人数,Q为查询次数.输入K个正整数,分别代表每 ...
- Array数组的方法总结
1.检测数组 自从ECMAScript3作出规定后,就出现了确定某个对象是不是数组的经典问题.对于一个网页,或者一个全局作用域而言,使用instanceof操作符就能得到满意结果. if (value ...