May 2009 - May 2017 论坛八周年-你的足迹,我的骄傲



查看: 302|回复: 0

[找工就业] 一道OA题目 求思路

[复制链接] |试试Instant~ |关注本帖
snakefly 发表于 2016-2-4 11:30:22 | 显示全部楼层 |阅读模式

2016(4-6月)-[15]CS硕士+fresh grad 无实习/全职 - Other| 码农类其他@fresh grad应届毕业生


您需要 登录 才可以下载或查看,没有帐号?获取更多干活,快来注册

来自codeassess  求这里的OA tips.

. Waral 鍗氬鏈夋洿澶氭枃绔,

Write a program that takes one integer N and an array of N * N elements (the first line contains the integer N and the next N lines contain N integers each, representing the two dimensional array). Your program should give as output the size of the maximum square array (an array of size M * M) that is a magic square and is a sub-array of the inputted array. A magic square is a square of numbers such that when you pick any set of N cells from that square, each cell from the set doesn't share a row or a column with any other cell from that set, and the sum of those N cells is the same for each such possible set of cells.


Case 1:. 鐗涗汉浜戦泦,涓浜╀笁鍒嗗湴

For the input provided as follows:

23 40
9 26. from:

Output of the program will be:


As 23 + 26 is equal to 40 + 9, the inputted array is a magic square, giving us a maximum answer of 2.

Case 2:

For the input provided as follows:
-41 -29 2 1
28 40 71 2
11 23 54 3. more info on
4 5 6 7 8

Output of the program will be:

. more info on

As the inputted array is not a magic square, the answer can not be 4. Looking at all the possible square arrays, we can check that the maximum answer is 3 with the following 3 x 3 array:

-41 -29 2 鏉ユ簮涓浜.涓夊垎鍦拌鍧.
28 40 71
11 23 54



一亩三分地推荐上一条 /5 下一条

手机版|小黑屋|一亩三分地论坛声明 ( 沪ICP备11015994号 )

custom counter

GMT+8, 2017-5-26 06:08

Powered by Discuz! X3

© 2001-2013 Comsenz Inc. Design By HUXTeam

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