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 9This 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
旋转.....用分治做或许更好,但是为了理解今天特地用模拟做了一次.....
代码如下:
 #include<iostream>
#include<cstdio>
using namespace std;
int min(int a,int b)
{
return a<b?a:b;
}
int main()
{
int n,i,j,max,pos,tpos;
int str[][],sum;
while(cin>>n,n)
{
for(i=;i<=n;i++) //输入部分
{
for(j=;j<=n;j++)
scanf("%d",str[i]+j);
}
pos=;
max=str[(n+)/][(n+)/];
for(i= ; i<=(n-)/ ; i++) //圈数
{
for(j=i;j<=n-i;j++)
{
int temp=(str[j][i]+str[n-j+][n-i+])+(str[n-i+][j]+str[i][n-j+]); //主副对角线相加
if(j==i||sum<temp)
sum=temp,tpos=min(j-i,n-(i+j)+);
}
pos+=tpos;
max+=sum;
}
printf("%d %d\n",max,pos);
}
return ;
}

HDUOJ---(4708)Rotation Lock Puzzle的更多相关文章

  1. hduoj 4708 Rotation Lock Puzzle 2013 ACM/ICPC Asia Regional Online —— Warmup

    http://acm.hdu.edu.cn/showproblem.php?pid=4708 Rotation Lock Puzzle Time Limit: 2000/1000 MS (Java/O ...

  2. HDU 4708:Rotation Lock Puzzle

    Rotation Lock Puzzle Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  3. HDU 4708 Rotation Lock Puzzle (简单题)

    Rotation Lock Puzzle Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  4. HDU 4708 Rotation Lock Puzzle(模拟)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4708 题目大意:给定一个方形矩阵,边长为3-10的奇数.每一圈的数字可以沿着顺时针方向和逆时针方向旋转 ...

  5. hdu 4708 Rotation Lock Puzzle 2013年ICPC热身赛A题 旋转矩阵

    题意:给出一个n*n的矩阵,旋转每一圈数字,求出对角线可能的最大值,以及转到最大时的最小距离. 只要分析每一层就可以了,本来想用地址传递二维数组,发现行不通,改了一下就行了. 这里有个坑,比如: 1 ...

  6. hdu4708 Rotation Lock Puzzle

    Rotation Lock Puzzle Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...

  7. Rotation Lock Puzzle

    Problem Description Alice was felling into a cave. She found a strange door with a number square mat ...

  8. Codeforces Round #467 (Div. 2) E -Lock Puzzle

    Lock Puzzle 题目大意:给你两个字符串一个s,一个t,长度<=2000,要求你进行小于等于6100次的shift操作,将s变成t, shift(x)表示将字符串的最后x个字符翻转后放到 ...

  9. Codeforces Round #467 (Div. 1). C - Lock Puzzle

    #include <algorithm> #include <cstdio> #include <cstring> #include <iostream> ...

随机推荐

  1. PASCAL VOC数据集The PASCAL Object Recognition Database Collection

    The PASCAL Object Recognition Database Collection News 04-Apr-07: The VOC2007 challenge development ...

  2. 数学图形之克莱因瓶(klein bottle)

    克莱因瓶是一种内外两面在同一个曲面上的图形. 在数学领域中,克莱因瓶(德语:Kleinsche Flasche)是指一种无定向性的平面,比如二维平面,就没有“内部”和“外部”之分.克莱因瓶最初的概念提 ...

  3. Android中XML解析-Dom解析

    Android中需要解析服务器端传过来的数据,由于XML是与平台无关的特性,被广泛运用于数据通信中,有的时候需要解析xml数据,格式有三种方式,分别是DOM.SAX以及PULL三种方式,本文就简单以D ...

  4. HTML标签 闭合还是不闭合?

    你在写 HTML5 代码的时候,是否纠结过应该写 <br /> 还是 <br>,是写 <input /> 还是写 <input>.写 <scrip ...

  5. jQuery的搜索关键词自动匹配插件

    相信许多人都会用过搜索栏自动匹配关键词的功能,无论是像google的专业搜索引擎,还是普通的网站,现在许多都用上了这种关键词匹配技术,本文介绍的用jQuery实现的关键词匹配技术,当然要整合到自己的系 ...

  6. Java基础(四):Java Number & Math 类、Character 类、String 类、StringBuffer & StringBuilder 类

    一.Java Number & Math 类: 1.Number类: 一般地,当需要使用数字的时候,我们通常使用内置数据类型,如:byte.int.long.double 等.然而,在实际开发 ...

  7. [置顶] Android异步加载数据库和多线程编程

    Android是一种基于Linux的自由及开放源代码的操作系统,主要使用于移动设备,如智能手机和平板电脑,由Google公司和开放手机联盟领导及开发.尚未有统一中文名称,中国大陆地区较多人使用“安卓” ...

  8. GridControl 获取某分组的第一个孩子

    int iGroupRowHandle = this.gridControlView.FocusedRowHandle; ) { int iChildCount = this.gridControl. ...

  9. Maven deploy Return code is: 400

    Maven deploy Return code is: 400 学习了:https://blog.csdn.net/running_snail_/article/details/19821777 H ...

  10. C#.NET常见问题(FAQ)-如何在系统变量中加入新的环境变量

    比如我要将C:\Windows\Microsoft.NET\Framework\v3.5这个目录加入环境变量 则在系统的环境变量中点击Path,编辑,然后加入一个分号";",然后粘 ...