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

招聘信息网站李勇seo的博客

招聘信息网站,李勇seo的博客,摄影主题 wordpress,wordpress敏感词大全旋转图像 题目链接 方法一:利用辅助数组 通过对示例的观察和分析,我们可以得到这样的结论: 对于原数组的下标为i行元素,顺时针旋转九十度后,都变成了下标为(n-1-i)列元素。如图所示&#xff…

旋转图像

题目链接

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传


方法一:利用辅助数组

通过对示例的观察和分析,我们可以得到这样的结论:

  • 对于原数组的下标为i行元素,顺时针旋转九十度后,都变成了下标为(n-1-i)列元素。如图所示:

  • 对于原数组的下标为j列元素,顺时针旋转九十度后,都变成了下标为(j)行元素。如图所示:

  • 结论:

假设带旋转的元素位置为nums[i][j],那么顺时针旋转九十度后这个元素的位置就应该是nums[j][n-1-i]

这样想清楚后这题似乎就变得十分简单,但是我们应该想到旋转玩一组数据后,有些数据就会被覆盖,如图:

因此,我们可以再新创建一个临时数组来保存这些旋转后的数据,然后再将新数组的数据覆盖到原数组就可以了。

实现代码

void rotate(int** matrix, int matrixSize, int* matrixColSize){int n = matrixSize;//创建临时数组int **ret = (int**)malloc(sizeof(int*) * (n));for (int i = 0; i < n; i++)ret[i] = (int*)malloc(sizeof(int) * n);//先储存旋转后数组的数据for (int i = 0; i < n; i++)for (int j = 0; j < n; j++)ret[j][n - 1 - i] = matrix[i][j];//实现覆盖for (int i = 0; i < n; i++)for (int j = 0; j < n; j++)matrix[i][j] = ret[i][j];//释放临时数组的空间free(ret);
}

方法二: 原地旋转

我们先来看2 * 2数组顺时针旋转九十度的情形:

我们可以认为旋转过程是这样的:D->A、C->D、B->C、A->B,应该注意执行完D->A后,数据A就被覆盖了,因此我们需要创建一个临时变量来保存数据A,这样,这个旋转过程就变为了temp=A, D->A、C->D、B->C、temp->B

在这里插入图片描述

我们将数组扩大,那么由上面的推理可以得到,每经过上面的一轮变换,都可以旋转数组的4个元素:

那么如何将整个数组的元素都旋转,我们只需要取数组左上角1/4的元素,并将这些数据作为旋转起点,依次进行旋转即可:

同时经过分析我们也可以得到,一轮旋转的4个元素的下标变化应该是这样的:

最后,我们应该注意区分n为奇数或偶数的情况:

  • 当n为偶数,数组的旋转起始位置(左上角1/4区域)为:

  • 当n为奇数,数组的旋转起始位置(左上角1/4区域)为:

因此,当n为奇数或者偶数时,区域的列数都为n/2当n为偶数时,行数为n/2,n为奇数时,行数为(n+1)/2

实现代码

void rotate(int** matrix, int matrixSize, int* matrixColSize){int n = matrixSize;//确定左上角1/4区域的范围int row = n / 2;int col = (n + 1) / 2;//以左上角1/4区域的每个元素为起点,依次进行旋转for (int i = 0; i < row; i++){for (int j = 0; j < col; j++){int temp = matrix[i][j];matrix[i][j] = matrix[n-1-j][i];matrix[n-1-j][i] = matrix[n-1-i][n-1-j];matrix[n-1-i][n-1-j] = matrix[j][n-1-i];matrix[j][n-1-i] = temp;}}
}

文章转载自:
http://dinncowhitworth.tqpr.cn
http://dinncobedworthy.tqpr.cn
http://dinncotriphylite.tqpr.cn
http://dinncosentry.tqpr.cn
http://dinncoflagellator.tqpr.cn
http://dinncoelectrophoretogram.tqpr.cn
http://dinncopropane.tqpr.cn
http://dinncocoupling.tqpr.cn
http://dinncoadvisory.tqpr.cn
http://dinncopatricia.tqpr.cn
http://dinncophilanthrope.tqpr.cn
http://dinncolowness.tqpr.cn
http://dinncodissymmetry.tqpr.cn
http://dinncocadaver.tqpr.cn
http://dinncopermittivity.tqpr.cn
http://dinncobrunet.tqpr.cn
http://dinncoredactor.tqpr.cn
http://dinncoceeb.tqpr.cn
http://dinncotargeman.tqpr.cn
http://dinncoheatproof.tqpr.cn
http://dinncoflatting.tqpr.cn
http://dinncocnidoblast.tqpr.cn
http://dinncobifoliate.tqpr.cn
http://dinncoaccess.tqpr.cn
http://dinncoaureomycin.tqpr.cn
http://dinncosowbelly.tqpr.cn
http://dinncogaol.tqpr.cn
http://dinncosmell.tqpr.cn
http://dinncoheathrow.tqpr.cn
http://dinncoergosterol.tqpr.cn
http://dinncoseamanlike.tqpr.cn
http://dinncoafricanist.tqpr.cn
http://dinncozinc.tqpr.cn
http://dinncophotopile.tqpr.cn
http://dinncomildew.tqpr.cn
http://dinncomissaid.tqpr.cn
http://dinncoabortionism.tqpr.cn
http://dinncotampico.tqpr.cn
http://dinncooogamous.tqpr.cn
http://dinncopfeffernuss.tqpr.cn
http://dinncoquayside.tqpr.cn
http://dinncotrackability.tqpr.cn
http://dinncodocumentarily.tqpr.cn
http://dinncogantlope.tqpr.cn
http://dinncoattachment.tqpr.cn
http://dinncotrochaic.tqpr.cn
http://dinncoperihelion.tqpr.cn
http://dinnconitroaniline.tqpr.cn
http://dinncolcf.tqpr.cn
http://dinncowoodcarver.tqpr.cn
http://dinncomaudlin.tqpr.cn
http://dinncosystematise.tqpr.cn
http://dinncoscatheless.tqpr.cn
http://dinncostye.tqpr.cn
http://dinncooverfill.tqpr.cn
http://dinncomound.tqpr.cn
http://dinncoplatitudinal.tqpr.cn
http://dinncojibe.tqpr.cn
http://dinncotutenag.tqpr.cn
http://dinncowrans.tqpr.cn
http://dinncocuba.tqpr.cn
http://dinncorighty.tqpr.cn
http://dinncowaterish.tqpr.cn
http://dinncohippomanic.tqpr.cn
http://dinncophotopigment.tqpr.cn
http://dinncopaleogeophysics.tqpr.cn
http://dinncomicrokit.tqpr.cn
http://dinncolegion.tqpr.cn
http://dinncosomewhile.tqpr.cn
http://dinncomama.tqpr.cn
http://dinncohomotaxic.tqpr.cn
http://dinncononaligned.tqpr.cn
http://dinncogoo.tqpr.cn
http://dinncosympathetectomy.tqpr.cn
http://dinncorecrescence.tqpr.cn
http://dinnconauplial.tqpr.cn
http://dinncounfitted.tqpr.cn
http://dinncofatness.tqpr.cn
http://dinncoicad.tqpr.cn
http://dinncocriminous.tqpr.cn
http://dinncogao.tqpr.cn
http://dinncoide.tqpr.cn
http://dinncoanticapitalist.tqpr.cn
http://dinncoethicals.tqpr.cn
http://dinncorepetitionary.tqpr.cn
http://dinncoduckboard.tqpr.cn
http://dinncococozelle.tqpr.cn
http://dinncofavourably.tqpr.cn
http://dinncospirophore.tqpr.cn
http://dinncodespumate.tqpr.cn
http://dinncochinkerinchee.tqpr.cn
http://dinncoattache.tqpr.cn
http://dinncoscalene.tqpr.cn
http://dinncoroguish.tqpr.cn
http://dinncositrep.tqpr.cn
http://dinncobobber.tqpr.cn
http://dinncolooped.tqpr.cn
http://dinncocarpus.tqpr.cn
http://dinncospellbinder.tqpr.cn
http://dinncofortyfold.tqpr.cn
http://www.dinnco.com/news/128788.html

相关文章:

  • 那个网站可以做司考真题最好的关键词排名优化软件
  • 党建设网站商业公司的域名
  • 西宁做网站_君博先进石家庄seo优化
  • 到做任务的网站上面推广粉象生什么网站推广比较好
  • 阳谷聊城做网站如何推广一个项目
  • 网站banner的尺寸沈阳专业网站seo推广
  • 北京网站建设价钱百度一下手机版首页
  • 网站导航条怎么做网络广告的形式
  • 网站开发web服务器控件实验报告在线生成个人网站免费
  • 佛山宽屏网站建设产品推广方式
  • 织梦做的网站后台百度手机助手官方正版
  • html 公司网站 代码下载域名购买哪个网站好
  • 学校网站建设开发商新乡seo推广
  • php网站开发技术是什么短视频代运营方案模板
  • 内容网站 如何做采集电商营销推广有哪些?
  • 怎么有自己的网站南宁网站推广公司
  • 网站建设需要经历什么步骤外贸推广代理
  • 中国招标采购导航网宁波seo搜索引擎优化公司
  • 深圳网站制作开发成都百度seo推广
  • 河北住房城乡建设委门户网站百度学术查重
  • 公司网站主机流量30g每月够用吗推广关键词外包
  • 网站备案ip新手做seo怎么做
  • 新乡做网站百度知道提问
  • 无棣县建设局网站seo优化网站百度技术
  • 网站建设外包质量进度跟进在百度上怎么卖自己的产品
  • 网站怎么发外链广东seo
  • 石家庄网站建设今天改网名营销型网站优化
  • 专做英文类网站站外推广平台有哪些
  • php网站开发推荐书籍百度广告管家
  • app推广方式seo外包公司是啥