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. RHPAM 7.2安装

    1.产品架构 2.安装过程 下载相应介质 JBoss EAP (jboss-eap-7.2.0.zip)   下载地址 https://developers.redhat.com/products/e ...

  2. 我所遭遇过的中间件--3D MAX SDK

    搞图形的人都知道3D MAX,而3D MAX SDK就是在该软件基础上的一套软件开发包.至于该不该将3D MAX SDK归纳为中间件,不要在意这细节了,反正我觉得SDK和中间件就差不多是一个东西.实际 ...

  3. Interpreter Expression 解释器模式 MD

    解释器模式 简介 Interpreter模式也叫解释器模式,是行为模式之一,它是一种特殊的设计模式,它建立一个解释器,对于特定的计算机程序设计语言,用来解释预先定义的文法. 应用环境: 如果一种特定类 ...

  4. 用于Web开发的8 个最好的跨平台编辑器

    1) Best Cross Platform IDE - Brackets Brackets是一个在前端Web开发和设计人员中最流行的开放源码IDE/代码编辑器之一.它拥有一些实用工具能够将HTML ...

  5. Android -- SDcard文件读取和保存

    背景                                                                                            一些东西可以 ...

  6. 【SpringBoot】SpringBoot性能优化

    Spring 框架给企业软件开发者提供了常见问题的通用解决方案,包括那些在未来开发中没有意识到的问题.但是,它构建的 J2EE 项目变得越来越臃肿,逐渐被 Spring Boot 所替代.Spring ...

  7. [Algorithm] Serialize and Deserialize Binary Tree

    Given the root to a binary tree, implement serialize(root), which serializes the tree into a string, ...

  8. (数据挖掘-入门-6)十折交叉验证和K近邻

    主要内容: 1.十折交叉验证 2.混淆矩阵 3.K近邻 4.python实现 一.十折交叉验证 前面提到了数据集分为训练集和测试集,训练集用来训练模型,而测试集用来测试模型的好坏,那么单一的测试是否就 ...

  9. Linux:编译动态库时遇到的错误relocation R_X86_64_32 against `a local symbol'

    编译动态库时遇到如下错误: ... ... relocation R_X86_64_32 against `a local symbol' can not be used when making a ...

  10. rapidxml 序列化

    void TestRapidXml() { ]; sprintf(xmlContent,"<root><head>aaa</head><body&g ...