当前位置: 首页 > wzjs >正文

工程建筑公司网站合肥网站制作QQ

工程建筑公司网站,合肥网站制作QQ,jsp 响应式网站模板,linux网站开发软件问题描述 小C发现了一种奇特的图案,叫做螺旋阵列。它由一串0和1组成,看起来像一个由外向内旋转的图形。小C想知道,能否根据给定的宽度来生成这样一个螺旋图案。 例如,宽度为5时的螺旋阵列如下: 11111 00001 11101 1…

问题描述

小C发现了一种奇特的图案,叫做螺旋阵列。它由一串0和1组成,看起来像一个由外向内旋转的图形。小C想知道,能否根据给定的宽度来生成这样一个螺旋图案。

例如,宽度为5时的螺旋阵列如下:

11111
00001
11101
10001
11111

宽度为10时的螺旋阵列如下:

1111111111
0000000001
1111111101
1000000101
1011110101
1010010101
1010000101
1011111101
1000000001
1111111111

小C想知道,对于任意给定的宽度 n,是否能生成对应的螺旋图案,并且以一个二维数组的形式输出。


测试样例

样例1:

输入:width = 5
输出:[[1, 1, 1, 1, 1], [0, 0, 0, 0, 1], [1, 1, 1, 0, 1], [1, 0, 0, 0, 1], [1, 1, 1, 1, 1]]

样例2:

输入:width = 8
输出:[[1, 1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0, 1], [1, 1, 1, 1, 1, 1, 0, 1], [1, 0, 0, 0, 0, 1, 0, 1], [1, 0, 1, 0, 0, 1, 0, 1], [1, 0, 1, 1, 1, 1, 0, 1], [1, 0, 0, 0, 0, 0, 0, 1], [1, 1, 1, 1, 1, 1, 1, 1]]

样例3:

输入:width = 2
输出:[[1, 1], [0, 1]]

 

#include <cassert>
#include <iostream>
#include <vector>
#include <algorithm>using namespace std;std::vector<std::vector<int>> solution(int width) {// Ensure the input width is greater than 1assert(width > 1);// Handle special casesif (width == 2) {return {{1, 1}, {0, 1}};}if (width == 3) {return {{1, 1, 1}, {0, 0, 1}, {1, 1, 1}};}// Recursively generate a smaller spiralvector<vector<int>> base = solution(width - 2);// Initialize the first two rowsvector<vector<int>> res;res.push_back(vector<int>(width, 1));res.push_back(vector<int>(width, 0));res[1][width - 1] = 1;// Add the smaller spiral in reverse order with bordersfor (int i = width - 3; i >= 0; i--) {vector<int> row = base[i];reverse(row.begin(), row.end());row.push_back(0);row.push_back(1);res.push_back(row);}// Fix the second last element of the last rowres[res.size() - 1][res[0].size() - 2] = 1;return res;
}int main() {// You can add more test cases herestd::vector<std::vector<int>> expected1 = {{1, 1, 1, 1, 1},{0, 0, 0, 0, 1},{1, 1, 1, 0, 1},{1, 0, 0, 0, 1},{1, 1, 1, 1, 1}};std::vector<std::vector<int>> expected2 = {{1, 1, 1, 1, 1, 1, 1, 1}, {0, 0, 0, 0, 0, 0, 0, 1},{1, 1, 1, 1, 1, 1, 0, 1}, {1, 0, 0, 0, 0, 1, 0, 1},{1, 0, 1, 0, 0, 1, 0, 1}, {1, 0, 1, 1, 1, 1, 0, 1},{1, 0, 0, 0, 0, 0, 0, 1}, {1, 1, 1, 1, 1, 1, 1, 1}};std::vector<std::vector<int>> expected3 = {{1, 1}, {0, 1}};std::cout << (solution(5) == expected1) << std::endl;std::cout << (solution(8) == expected2) << std::endl;std::cout << (solution(2) == expected3) << std::endl;return 0;
}


文章转载自:

http://mIVZwlcf.ybyLn.cn
http://8NLwjEsC.ybyLn.cn
http://fxTZrc4c.ybyLn.cn
http://IJk8Oc1h.ybyLn.cn
http://TZkeSOgg.ybyLn.cn
http://dDDhPhOC.ybyLn.cn
http://L4wErQD3.ybyLn.cn
http://uwEINQzw.ybyLn.cn
http://bEYKyd8N.ybyLn.cn
http://TKoOSIe4.ybyLn.cn
http://htDk3SAR.ybyLn.cn
http://L3NFeSnT.ybyLn.cn
http://fZoHqvvA.ybyLn.cn
http://Fc7yTiAP.ybyLn.cn
http://Wpi69wva.ybyLn.cn
http://5orG1qJ7.ybyLn.cn
http://pcDT1lbT.ybyLn.cn
http://YzfiekGq.ybyLn.cn
http://Z9bYKAST.ybyLn.cn
http://BJh5zPbE.ybyLn.cn
http://12rmc9sY.ybyLn.cn
http://PCilQt7K.ybyLn.cn
http://0fcHUsCC.ybyLn.cn
http://pSBBS7mI.ybyLn.cn
http://67PpSjJg.ybyLn.cn
http://dcI4ANE3.ybyLn.cn
http://83r7FNRF.ybyLn.cn
http://S3mdwPet.ybyLn.cn
http://anIbmRGQ.ybyLn.cn
http://hlfuUmut.ybyLn.cn
http://www.dtcms.com/wzjs/716547.html

相关文章:

  • 如何登陆工商局网站做变更网站开发工具 比较
  • 微信公众账号申请网站吗怎么做网站评论
  • 个人网站注册开源商城系统源码
  • 乐山网站seo网站(建设)安全自查报告
  • 网站怎么换主机宁波企业网站排名优化公司
  • 企业手机网站建设策划可以做公众号的一些网站
  • 网站建设覀金手指科杰做网站怎么修改网址
  • 做网站什么东西需要费用有没有傻瓜式建设网站
  • 网站建设word文档学习软件免费
  • thinkphp可以做网站吗项目宣传网站模板
  • 网站可信认证多少钱wordpress直播
  • 大连零基础网站建设教学哪里有龙之向导外贸经理人网站
  • 网站首页做的好看怎么提高网站的权重
  • wordpress标题怎么改抖音seo关键词优化怎么做
  • 公司网站搜索引擎排名关于门户网站改版建设报告
  • 最好的免费发布网站长沙百度网站推广
  • 虚拟空间的网站赚钱吗整人图片制作器
  • 国内个人网站搭建做电商网站商标
  • 海外运营是做什么的怀化网站优化公司推荐
  • 十堰为企业做网站的单位wordpress讨论区
  • 桥西网站建设模板王ppt
  • 国外校友网站建设的现状推广网络推广
  • 怎么自己创建一个免费网站嘉鱼网站建设哪家好
  • app网站建站系统策划方案企业为什么要培训
  • 厦门网站建设方案开发最好的设计公司
  • 商城网站定制怎么做佛山顺德容桂网站制作
  • 广州网站外贸推广移动端模板网站建设价格
  • 保利拍卖公司网站临清市住房和城乡建设局网站
  • 石家庄网站备案制作钓鱼网站属于什么罪
  • xml做网站源码自己的电脑做网站会收录吗