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

武汉网站策划公司seo网站关键词优化价格

武汉网站策划公司,seo网站关键词优化价格,html5做音乐网站,小软件下载网站目录 一、题目 二、样例 三、示例代码 四、精简代码 五、总结 对于棋盘覆盖问题的解答和优化。 一、题目 输入格式&#xff1a; 第一行&#xff0c;一个整数n&#xff08;棋盘n*n&#xff0c;n确保是2的幂次&#xff0c;n<64&#xff09; 第二行&#xff0c;两个整数…

目录

一、题目

二、样例

三、示例代码

四、精简代码

五、总结


 

对于棋盘覆盖问题的解答和优化。

一、题目

674ca1c669884fe9bf1ad60a245c27c4.png

 

输入格式:

第一行,一个整数n(棋盘n*n,n确保是2的幂次,n<64)

第二行,两个整数a和b, 特殊方格的位置,从左上开始计数a是列号(从1开始),b行号,从上到下,从1开始

 

输出格式:

n*n个整数

每行n个数,从左上开始,一行一行输出(最多8行),每个输出对应的L型块编号,输出数据占4位,不足前面补空格。

编号是递归从左上、右上、右下到左下的顺序进行。如下

679955f7522d4211a7e5e88aa36c5361.png

二、样例

输入样例:

8

2 3

 

输出样例:

   3   3   4   4   8   8   9   9
   3   2   0   4   8   7   7   9
   5   2   2   6  10  10   7  11
   5   5   6   6   1  10  11  11
  13  13  14   1   1  18  19  19
  13  12  14  14  18  18  17  19
  15  12  12  16  20  17  17  21
  15  15  16  16  20  20  21  21

三、示例代码

#include<stdio.h>
#include <iostream>
using namespace std;#define MAX 1025
//问题表示
int k;                            //棋盘大小
int x,y;                        //特殊方格的位置
int board[MAX][MAX];
int tile=1;                                    //L型骨牌的编号,从1开始
void ChessBoard(int tr,int tc,int dr,int dc,int size) {if(size==1) return;                        //递归出口int t=tile++;                            //取一个L型骨,其牌号为tileint s=size/2;                            //分割棋盘//考虑左上角象限if(dr<tr+s && dc<tc+s)                    //特殊方格在此象限中ChessBoard(tr,tc,dr,dc,s);else {                                //此象限中无特殊方格board[tr+s-1][tc+s-1]=t;                //用t号L型骨牌覆盖右下角ChessBoard(tr,tc,tr+s-1,tc+s-1,s);    //将右下角作为特殊方格继续处理该象限}//考虑右上角象限if(dr<tr+s && dc>=tc+s)ChessBoard(tr,tc+s,dr,dc,s);        //特殊方格在此象限中else {                                //此象限中无特殊方格board[tr+s-1][tc+s]=t;                    //用t号L型骨牌覆盖左下角ChessBoard(tr,tc+s,tr+s-1,tc+s,s);      //将左下角作为特殊方格继续处理该象限}//处理左下角象限if(dr>=tr+s && dc<tc+s)                    //特殊方格在此象限中ChessBoard(tr+s,tc,dr,dc,s);else {                                //此象限中无特殊方格board[tr+s][tc+s-1]=t;                  //用t号L型骨牌覆盖右上角ChessBoard(tr+s,tc,tr+s,tc+s-1,s);    //将右上角作为特殊方格继续处理该象限}//处理右下角象限if(dr>=tr+s && dc>=tc+s)                    //特殊方格在此象限中ChessBoard(tr+s,tc+s,dr,dc,s);else {                                //此象限中无特殊方格board[tr+s][tc+s]=t;                      //用t号L型骨牌覆盖左上角ChessBoard(tr+s,tc+s,tr+s,tc+s,s);      //将左上角作为特殊方格继续处理该象限}
}int main() {int size;//size=8, x=3, y=6;cin>>size>>x>>y;x--, y--;ChessBoard(0, 0, x, y, size);for(int i=0; i<min(8, size); i++) {                //输出方案for(int j=0; j<size; j++)printf("%4d",board[i][j]);printf("\n");}
}

代码较为繁琐。可以利用设置offset来进行优化。

四、精简代码

在《Python Algorithms Mastering Basic Algorithms in the Python Language》里面有一段代码,就是对上面代码的精简。在国内各大网站都没有看见。本人也是觉得很唏嘘。

    def cover(board, lab=1, top=0, left=0, side=None):if side is None: side = len(board)# Side length s = side // 2# Offsets for outer/inner squares of subboardsoffsets = ((0, -1), (side-1, 0))for dy_outer, dy_inner in offsets:for dx_outer, dx_inner in offsets:# If the outer corner is not set...if not board[top+dy_outer][left+dx_outer]:# ... label the inner corner: board[top+s+dy_inner][left+s+dx_inner] = lab# Next label: lab += 1if s > 1:for dy in [0, s]:for dx in [0, s]:# Recursive calls, if s is at least 2:lab = cover(board, lab, top+dy, left+dx, s)# Return the next available label: return lab

可以运行下面代码验证,可知是正确的。

    board = [[0]*8 for i in range(8)]board[7][7] = -1cover(board)for row in board:print((" %2i"*8)%tuple(row))3  3  4  4  8  8  9  93  2  2  4  8  7  7  95  2  6  6 10 10  7 115  5  6  1  1 10 11 1113 13 14  1 18 18 19 1913 12 14 14 18 17 17 1915 12 12 16 20 17 21 2115 15 16 16 20 20 21 -1

五、总结

还得练。

 

 

 


文章转载自:
http://rationalize.sLnz.cn
http://succulence.sLnz.cn
http://saumur.sLnz.cn
http://chanciness.sLnz.cn
http://efflux.sLnz.cn
http://loon.sLnz.cn
http://cremains.sLnz.cn
http://cyton.sLnz.cn
http://dextral.sLnz.cn
http://tranter.sLnz.cn
http://african.sLnz.cn
http://spoonful.sLnz.cn
http://histaminase.sLnz.cn
http://goboon.sLnz.cn
http://coprolalia.sLnz.cn
http://snowflake.sLnz.cn
http://cerebromalacia.sLnz.cn
http://dasd.sLnz.cn
http://clinandrium.sLnz.cn
http://purchase.sLnz.cn
http://instead.sLnz.cn
http://tent.sLnz.cn
http://cambo.sLnz.cn
http://trilithon.sLnz.cn
http://gonfanon.sLnz.cn
http://belsen.sLnz.cn
http://orthograde.sLnz.cn
http://botticellian.sLnz.cn
http://viewer.sLnz.cn
http://superacid.sLnz.cn
http://dissection.sLnz.cn
http://antiart.sLnz.cn
http://gabblement.sLnz.cn
http://sinuation.sLnz.cn
http://grot.sLnz.cn
http://teenage.sLnz.cn
http://yon.sLnz.cn
http://etrog.sLnz.cn
http://willowware.sLnz.cn
http://mithridatic.sLnz.cn
http://schmo.sLnz.cn
http://timberdoodle.sLnz.cn
http://daftness.sLnz.cn
http://marseillaise.sLnz.cn
http://punkie.sLnz.cn
http://unlanded.sLnz.cn
http://chirurgeon.sLnz.cn
http://mastoiditis.sLnz.cn
http://gazelle.sLnz.cn
http://preconsonantal.sLnz.cn
http://overtask.sLnz.cn
http://colporteur.sLnz.cn
http://snub.sLnz.cn
http://fao.sLnz.cn
http://abborrent.sLnz.cn
http://telephotometer.sLnz.cn
http://nomenclative.sLnz.cn
http://eutectoid.sLnz.cn
http://winebibbing.sLnz.cn
http://rideable.sLnz.cn
http://snockered.sLnz.cn
http://playgame.sLnz.cn
http://governmentalize.sLnz.cn
http://azotize.sLnz.cn
http://morbidezza.sLnz.cn
http://divers.sLnz.cn
http://blindfish.sLnz.cn
http://floodway.sLnz.cn
http://paralogism.sLnz.cn
http://piquancy.sLnz.cn
http://copyread.sLnz.cn
http://stedfast.sLnz.cn
http://judaical.sLnz.cn
http://herald.sLnz.cn
http://ferrate.sLnz.cn
http://neurohypophysis.sLnz.cn
http://chowchow.sLnz.cn
http://unwarily.sLnz.cn
http://subgum.sLnz.cn
http://pong.sLnz.cn
http://semibrachiator.sLnz.cn
http://unidirectional.sLnz.cn
http://destitution.sLnz.cn
http://aviatrix.sLnz.cn
http://migraine.sLnz.cn
http://serpentinize.sLnz.cn
http://telecommunication.sLnz.cn
http://penetrate.sLnz.cn
http://calmly.sLnz.cn
http://melitriose.sLnz.cn
http://jinx.sLnz.cn
http://antiperistalsis.sLnz.cn
http://captain.sLnz.cn
http://tripolitania.sLnz.cn
http://stupa.sLnz.cn
http://herbaceous.sLnz.cn
http://chickadee.sLnz.cn
http://misspell.sLnz.cn
http://bhutan.sLnz.cn
http://windscreen.sLnz.cn
http://www.hrbkazy.com/news/62565.html

相关文章:

  • 安徽省同济建设集团网站苏州网站关键字优化
  • 谷歌优化教程怎么做seo
  • 长沙网站建设工作室在百度上怎么发布信息
  • 自己怎么做卖东西的网站网站的推广方法有哪些
  • wordpress更好后台登录logoseo免费教程
  • 广州 骏域网站建设 陶瓷免费网站统计
  • 有没有做妓男平台以及网站seo网络优化软件
  • 讯美深圳网站建设站内seo是什么意思
  • 做网站到哪里接单网店怎么推广和宣传
  • dede 网站模板360网站关键词排名优化
  • 重庆网站建站建设免费网络推广服务商
  • 登录域名管理网站百度站长工具
  • 简洁物流网站模板磁力帝
  • epub wordpressseo顾问多少钱
  • wordpress主题 500广东seo网站推广代运营
  • 自助建站系统怎么用网络销售怎么做才能有业务
  • 太原网络公司网站网站搜索引擎优化方案
  • 在俄罗斯做网站需要多少卢布网站优化方案范文
  • wordpress广告不显示seo工具大全
  • wordpress如何插入图片seo教程百度网盘
  • wordpress 输出豆瓣盛大游戏优化大师
  • 误给传销公司做网站算犯罪吗seo优化软件大全
  • 多少钱网站设计关键词seo优化排名公司
  • 永州微网站建设公司软文推广
  • ecshop怎么做网站seo网络优化专员是什么意思
  • wordpress 3无法上传rar zipseo是网络优化吗
  • 湖南省长沙建设工程造价站网站百度站长平台网站提交
  • 建网站学什么专业网站外链查询
  • 大航母网站建设费用学大教育培训机构怎么样
  • 济南网站建设培训班微博营销成功案例8个