博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDUOJ---(4708)Rotation Lock Puzzle
阅读量:7207 次
发布时间:2019-06-29

本文共 2138 字,大约阅读时间需要 7 分钟。

Rotation Lock Puzzle

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 695    Accepted Submission(s): 204

Problem Description
Alice was felling into a cave. She found a strange door with a number square matrix. These numbers can be rotated around the center clockwise or counterclockwise. A fairy came and told her how to solve this puzzle lock: “When the sum of main diagonal and anti-diagonal is maximum, the door is open.”. Here, main diagonal is the diagonal runs from the top left corner to the bottom right corner, and anti-diagonal runs from the top right to the bottom left corner. The size of square matrix is always odd.
9 3 2 5 9
7 4 7 5 4
6 9 3 9 3
5 2 8 7 2
9 9 4 1 9
This sample is a square matrix with 5*5. The numbers with vertical shadow can be rotated around center ‘3’, the numbers with horizontal shadow is another queue. Alice found that if she rotated vertical shadow number with one step, the sum of two diagonals is maximum value of 72 (the center number is counted only once).
 
Input
Multi cases is included in the input file. The first line of each case is the size of matrix n, n is a odd number and 3<=n<=9.There are n lines followed, each line contain n integers. It is end of input when n is 0 .
 
Output
For each test case, output the maximum sum of two diagonals and minimum steps to reach this target in one line.
 
Sample Input
5
9 3 2 5 9
7 4 7 5 4
6 9 3 9 3
5 2 8 7 2
9 9 4 1 9
0
 
Sample Output
72
1
 
Source
 
Recommend
liuyiding
旋转.....用分治做或许更好,但是为了理解今天特地用模拟做了一次.....
代码如下:
1 #include
2 #include
3 using namespace std; 4 int min(int a,int b) 5 { 6 return a
>n,n)13 {14 for(i=1;i<=n;i++) //输入部分15 {16 for(j=1;j<=n;j++)17 scanf("%d",str[i]+j);18 }19 pos=0;20 max=str[(n+1)/2][(n+1)/2];21 for(i=1 ; i<=(n-1)/2 ; i++) //圈数22 {23 for(j=i;j<=n-i;j++)24 {25 int temp=(str[j][i]+str[n-j+1][n-i+1])+(str[n-i+1][j]+str[i][n-j+1]); //主副对角线相加26 if(j==i||sum
View Code

 

转载地址:http://nyoum.baihongyu.com/

你可能感兴趣的文章
第38周五
查看>>
windows下Emacs的安装与配置
查看>>
WF4 常用类<第二篇>
查看>>
mongo文件空间
查看>>
NSArray中存的是实体时的排序
查看>>
搜索框中“请输入搜索keyword”
查看>>
CentOS6.5与XP双系统安装
查看>>
Python 更新set
查看>>
shell语法简单介绍
查看>>
Web服务器的工作原理
查看>>
使用WinSetupFromUSB来U盘安装windowsXP(不使用win PE系统)
查看>>
JAVA Calendar具体解释
查看>>
MongoDB入门简单介绍
查看>>
Git show-branch显示提交信息
查看>>
秒杀 ILSpy 等反编译利器 DotNet Resolver
查看>>
SharePoint 2013 中代码创建列表查阅项字段
查看>>
2014仲秋校招之面试篇
查看>>
负载均衡研究 基础
查看>>
10.cadence.自定义焊盘的创建[原创]
查看>>
shell编程总结
查看>>