Love丶FFC's Blog

CCF-CSP_20150301:图像旋转

2019-10-24 15:45:14
阅读:1390   •   评论:23
标签:,

问题描述

旋转是图像处理的基本操作,在这个问题中,你需要将一个图像逆时针旋转90度。

计算机中的图像表示可以用一个矩阵来表示,为了旋转一个图像,只需要将对应的矩阵旋转即可。

输入格式

输入的第一行包含两个整数nm,分别表示图像矩阵的行数和列数。

接下来n行每行包含m个整数,表示输入的图像。

输出格式

输出m行,每行包含n个整数,表示原始矩阵逆时针旋转90度后的矩阵。

样例输入

2 3
1 5 3
3 2 4

样例输出

3 4
5 2
1 3

评测用例规模与约定

1 ≤ n≤ 1,000,矩阵中的数都是不超过1000的非负整数。

编程语言:Python

解题思想:

1.找出矩阵转换的规律: 转换前矩阵行的第i个元素是转换后矩阵的列的第(列数-i)个元素 。

2.为了减少使用的空间,在输入时就进行转换,而不是重开一个嵌套for循环进行转换。

本题最开始使用Java解题的时候,只拿了90分,就是因为内存超限,使用Python,因为代码简洁,解题思路也就清晰一些,所以用了尽量少的代码。

时间复杂度:O(n^2)

IDE代码如下:

  1. Row, Column = map(int, input().split()) # 输入矩阵的行和列
  2. Matrix = [[0 for i in range(Column)] for j in range(Row)] # 初始化矩阵
  3. ConvertMatrix = [[0 for i in range(Row)] for j in range(Column)] # 初始化旋转后的矩阵
  4.  
  5. for i in range(Row):
  6. Matrix[i] = [int(n) for n in input().split()] # 循环输入矩阵元素的值
  7. for j in range(Column):
  8. ConvertMatrix[j][i] = Matrix[i][Column - j - 1]
  9.  
  10. # 按格式要求输出旋转后的矩阵
  11. for i in range(Column):
  12. for j in range(Row):
  13. if j == Row - 1:
  14. print(ConvertMatrix[i][j]) # 每行最后一个元素输出并换行
  15. else:
  16. print(ConvertMatrix[i][j], end=" ") # 每行其它元素输出并空格
  17.  

评论板

共有 23 条评论

  1. Triemon

    Can you New Type 2 Diabetic Medicine can lasix make your blood sugar go up not use them this time Bai Tu said with a wry smile what is priligy dapoxetine Be direct about your wants desires, she will listen

  2. intuido

    PBMCs were isolated from healthy donor blood as described above and cultured in RPMI 1640 plus 10 fetal bovine serum at 37 C in 5 CO 2 buying cialis online reviews

  3. hi star golden goose

    WONDERFUL Post.thanks for share..extra wait .. ?

  4. ggdb shoes

    very nice publish, i definitely love this website, keep on it

  5. golden goose usa

    Howdy! I simply want to give a huge thumbs up for the nice data you’ve got right here on this post. I can be coming again to your weblog for more soon.

  6. travis scott jordan

    You made some decent factors there. I seemed on the internet for the issue and found most individuals will go along with together with your website.

  7. jordan 11

    There are actually a variety of particulars like that to take into consideration. That could be a great level to carry up. I provide the ideas above as general inspiration but clearly there are questions just like the one you carry up where crucial factor can be working in trustworthy good faith. I don?t know if finest practices have emerged around things like that, however I am positive that your job is clearly recognized as a fair game. Each girls and boys feel the influence of only a second抯 pleasure, for the rest of their lives.

  8. hi star golden goose

    I and also my guys were viewing the best recommendations located on your website and instantly developed a horrible suspicion I never thanked you for them. All the men were absolutely passionate to see them and have extremely been enjoying these things. Appreciate your getting so kind and also for making a decision on such fine subject areas millions of individuals are really wanting to know about. Our sincere apologies for not expressing appreciation to earlier.

  9. FWdZAdPq

    Another important consideration in relation to the currently available first generation prognostic signatures is that they were derived on the basis of the analysis of tissue samples with varying contents of neoplastic cells, stromal cells, inflammatory infiltrate, and normal breast tissue viagra pill identifier

  10. jordan shoes

    When I initially commented I clicked the -Notify me when new comments are added- checkbox and now each time a remark is added I get 4 emails with the identical comment. Is there any means you may take away me from that service? Thanks!

  11. kyrie 9

    Can I simply say what a aid to seek out someone who truly knows what theyre speaking about on the internet. You undoubtedly know tips on how to bring a difficulty to gentle and make it important. More individuals have to read this and perceive this aspect of the story. I cant believe youre not more well-liked because you definitely have the gift.

  12. air jordan shoes

    The next time I learn a blog, I hope that it doesnt disappoint me as much as this one. I mean, I know it was my option to learn, however I actually thought youd have something attention-grabbing to say. All I hear is a bunch of whining about one thing that you might fix in case you werent too busy in search of attention.

--------查看该分类下最新文章--------
^
新版博客正在完善中!域名:http://www.loveffc:8080,点击跳转,完全移植后将去除端口号。

Copyright © 2018 - 2021 FFC的小站 - 滇 ICP 备 18010780 号 - 1

- Powered by WordPress & AliYun · Theme by FFC -

- Environment by Windows & XAMPP · Designed by WebStorm & VSCode -

已运行:

访问量:493184