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

武汉网站建设排行google服务框架

武汉网站建设排行,google服务框架,株洲企业网站制作,百度网站下拉怎么做的一、zigzag打印矩阵 Z字形打印矩阵 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 打印顺序:1,2,7,13,8,3,4,9,14... 核心技巧:找到coding上的宏观调度 左上角有A、B两个点,A往右一步一步走,B往下一步一步走 写一个…

一、zigzag打印矩阵

Z字形打印矩阵
 1  2  3  4  5  6
 7  8  9  10 11 12
 13 14 15 16 17 18
打印顺序:1,2,7,13,8,3,4,9,14...

核心技巧:找到coding上的宏观调度

左上角有A、B两个点,A往右一步一步走,B往下一步一步走
写一个函数从左下往右上打印,调度问题交给点A和B来移动

package class09;/*** Z字形打印矩阵*/
public class Code06_ZigZagPrintMatrix {public static void printMatrixZigZag(int[][] matrix) {int aR = 0; //A的行号int aC = 0; //A的列号int bR = 0; //B的行号int bC = 0; //B的列号int endR = matrix.length - 1; //最后的行号int endC = matrix[0].length - 1; //最后的列号boolean fromUp = false; //是不是从右上往左下打印while (aR != endR + 1) { //A的行号,不等于最后的行号+1,A到了终点printLevel(matrix, aR, aC, bR, bC, fromUp);aR = (aC == endC ? aR + 1 : aR); //A的列数到最后一列,A的行号才加1aC = (aC == endC ? aC : aC + 1); //A的列数到最后一列,A的列数不变,否则A的列数加1bC = (bR == endR ? bC + 1 : bC); //B的行数到最后一行,B的列数加1,否则B的列数不变bR = (bR == endR ? bR : bR + 1); //B的行数到最后一行,B的行数不变,否则B的行数加1fromUp = !fromUp; //打印方向}System.out.println();}/*** 告诉你斜线的两端是A和B,方向也告诉你,就可以打印了* @param m* @param tR* @param tC* @param dR* @param dC* @param f*/public static void printLevel(int[][] m, int tR, int tC, int dR, int dC, boolean f) {if (f) {while (tR != dR + 1) { //右上往左下打印System.out.print(m[tR++][tC--] + " ");}} else {while (dR != tR - 1) { //左下往右上打印System.out.print(m[dR--][dC++] + " ");}}}public static void main(String[] args) {int[][] matrix = {{1,2,3,4},{5,6,7,8},{9,10,11,12},{13,14,15,16}};printMatrixZigZag(matrix);}
}

打印结果:

1 2 5 9 6 3 4 7 10 13 14 11 8 12 15 16 

二、转圈打印矩阵

按照层考虑:

第一层的结束的位置和第二层开始的位置挨着,第二层结束的位置和第三层开始的位置挨着。。。

思路:
获取四个角的点,打印时判断位置是否到四个角

package class09;/*** 回形打印矩阵*/
public class Code05_PrintMatrixSpiralOrder {public static void sprialOrderPrint(int[][] matrix) {int tR = 0;int tC = 0;int dR = matrix.length - 1;int dC = matrix[0].length - 1;while (tR <= dR && tC <= dC) {printEdge(matrix, tR++, tC++, dR--, dC--); //左上角点往右下方移动,右下角点往左上方移动}}/*** * @param m* @param tR 左上角点的行号* @param tC 左上角点的列号* @param dR 右下角点的行号* @param dC 右下角点的列号*/public static void printEdge(int[][] m, int tR, int tC, int dR, int dC) {if (tR == dR) { //是一条横线时for (int i = tC; i <= dC; i++) {System.out.print(m[tR][i] + " ");}} else if (tC == dC) { //是一条竖线时for (int i = tR; i <= dR; i++) {System.out.print(m[i][tC] + " ");}} else {int curC = tC;int curR = tR;while (curC != dC) {System.out.print(m[tR][curC] + " ");curC++;}while (curR != dR) {System.out.print(m[curR][dC] + " ");curR++;}while (curC != tC) {System.out.print(m[dR][curC] + " ");curC--;}while (curR != tR) {System.out.print(m[curR][tC] + " ");curR--;}}}public static void main(String[] args) {int[][] matrix = {{1,2,3,4},{5,6,7,8},{9,10,11,12},{13,14,15,16}};sprialOrderPrint(matrix);}
}

打印结果:

1 2 3 4 8 12 16 15 14 13 9 5 6 7 11 10 

三、原地旋转正方形矩阵

package class09;/*** 原地旋转正方形矩阵*/
public class Code04_RotateMatrix {public static void rotate(int[][] matrix) {int a = 0;int b = 0;int c = matrix.length - 1;int d = matrix[0].length - 1;while (a < c) { //只要关注行不越界rotateEdge(matrix, a++, b++, c--, d--);}}/*** 一个圈里面怎么转* @param m* @param a* @param b* @param c* @param d*/public static void rotateEdge(int[][] m, int a, int b, int c, int d) {int tmp = 0;for (int i = 0; i < d - b; i++) {tmp = m[a][b + i];m[a][b + i] = m[c - i][b];m[c - i][b] = m[c][d - i];m[c][d - i] = m[a + i][d];m[a + i][d] = tmp;}}public static void printMatrix(int[][] matrix) {for (int i = 0; i != matrix.length; i++) {for (int j = 0; j != matrix[0].length; j++) {System.out.print(matrix[i][j] + " ");}System.out.println();}}public static void main(String[] args) {int[][] matrix = {{1,2,3,4},{5,6,7,8},{9,10,11,12},{13,14,15,16}};printMatrix(matrix);System.out.println("====================");rotate(matrix);printMatrix(matrix);}
}

打印结果:

1 2 3 4 
5 6 7 8 
9 10 11 12 
13 14 15 16 
====================
13 9 5 1 
14 10 6 2 
15 11 7 3 
16 12 8 4 

http://www.dtcms.com/wzjs/422073.html

相关文章:

  • 广州公司做网站百度指数在线查询小程序
  • 自己提供域名做网站厦门百度seo排名
  • 公司做的网站列入什么科目推广普通话手抄报内容怎么写
  • 小程序开发外包费用seo服务建议
  • .top和网站注册城乡规划师含金量
  • 合肥品牌网站建设关键词推广方法
  • wordpress固定链接 重定向插件合肥seo网站管理
  • wordpress 自定义导航抖音seo搜索优化
  • 自己做同城购物网站市场推广方案模板
  • 超级工程网站建设白酒营销策划方案
  • 武汉专业网站建设报价广东最新新闻
  • 温州市城市建设学校网站计算机培训机构
  • 自己搭建服务器网站开发软件个人主页网页设计模板
  • 网站登录模版 下载seo是什么职业做什么的
  • 网站开发工具的app推广代理平台
  • 合肥市公司网站建设宁波seo托管公司
  • 视频直播系统开发网站建设外贸推广渠道有哪些
  • 学院网站建设成效网络营销方案案例
  • 网站后台数据黄页网络的推广软件
  • 大兴网站定制开发晋中网络推广
  • 外贸公司哪家好广州seo代理
  • 佛山seo整站优化丁香人才网官方网站
  • 做游戏女角色去衣的网站友情链接检查
  • 网站建设费进项税金可以抵扣吗b2b网站
  • 怎么做祝福的网站电子商务网站
  • 免费做网站哪里有适合口碑营销的产品
  • 品划做网站百度seo关键词排名技术
  • 投资建设网站首页seo软件全套
  • 做网站与全网营销搜索推广排名优化同城推广平台有哪些
  • 做愛网站魔贝课凡seo课程好吗