楼主: wrj5518
跳转到指定楼层
上一主题 下一主题
收起左侧

[CareerCup] 【第三轮】6.16-6.22 CareerCup 1.6

🔗
whiteflower 2014-7-4 18:10:03 | 只看该作者
全局:
【解题思路】preform a circular rotation on each layer
【时间复杂度】O(N^2)
【空间复杂度】O(1)
【gist link】https://gist.github.com/JoshuaTang/300b3e62fcc5449333a4
回复

使用道具 举报

🔗
pyemma 2014-7-6 19:02:51 | 只看该作者
全局:
【解题思路】First we need to know the scale of N to determine use what type to restore this number in order not to overflow, since each pixel uses only 4 bytes, int is enough, we assume that the rotation is anticlockwise. We only need to rotate the upper-left quater "square", replace each quater square iterately, however, this is only the case when N is even, when N is odd, the square has overlap and some pixle might be rotate more than one time. The responding position of pixel in each quater "square" is (i, j), (j, n-i), (n-i, n-j) and (n-j, i), this could be obtained recursively.
【时间复杂度】O(N2)
【空间复杂度】O(1)
【gist link】
https://gist.github.com/6af17484b1fc52138a23.git
---------------OPTional,如果觉得test case比较好,欢迎写出来分享----------------------
【test case】
回复

使用道具 举报

全局:
【解题思路】
rotate one layer by another, from outermost to innermost.

【时间复杂度】
O(n^2)


【空间复杂度】
O(1)


【gist link】
https://gist.github.com/happyWinner/cccb48c218c48b996fde

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册账号
隐私提醒:
  • ☑ 禁止发布广告,拉群,贴个人联系方式:找人请去🔗同学同事飞友,拉群请去🔗拉群结伴,广告请去🔗跳蚤市场,和 🔗租房广告|找室友
  • ☑ 论坛内容在发帖 30 分钟内可以编辑,过后则不能删帖。为防止被骚扰甚至人肉,不要公开留微信等联系方式,如有需求请以论坛私信方式发送。
  • ☑ 干货版块可免费使用 🔗超级匿名:面经(美国面经、中国面经、数科面经、PM面经),抖包袱(美国、中国)和录取汇报、定位选校版
  • ☑ 查阅全站 🔗各种匿名方法

本版积分规则

>
快速回复 返回顶部 返回列表