Rotation Lock Puzzle

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

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.

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
很简单的模拟!
 
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
using namespace std;
int map[12][12];
int main()
{
int i,j,n,maxx,maxstep,anss,ans;
while(scanf("%d",&n)!=EOF&&n)
{
for(i=0;i<n;i++)
for(j=0;j<n;j++)
scanf("%d",&map[i][j]);
int n2=n/2,temp;
ans=map[n2][n2];anss=0;
for(i=0;i<n2;i++)
{
int a=0; int i2=n-i*2;
maxx=map[i][i+a]+map[i+a][n-i-1]+map[n-i-a-1][i]+map[n-i-1][n-i-1-a];
maxstep=min(a,i2-1-a);
for(a=1;a<i2;a++)
{
temp=map[i][i+a]+map[i+a][n-i-1]+map[n-i-a-1][i]+map[n-i-1][n-i-1-a];
if(temp>maxx)
{
maxx=temp;
maxstep=min(a,i2-1-a);
}
else if(temp==maxx)
{
maxstep=min(maxstep,min(a,i2-1-a));
}
}
ans+=maxx;
anss+=maxstep;
}
printf("%d %d\n",ans,anss);
}
return 0;
}

Statistic |
Submit |
Discuss |
Note

hdu4708 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. HDUOJ---(4708)Rotation Lock Puzzle

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

  5. Rotation Lock Puzzle

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

  6. HDU 4708 Rotation Lock Puzzle(模拟)

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

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

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

  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. 条码的种类(types of barcode)

    条码基本上分为两大类:一维条码(1D Barcode)及二维条码(2D Barcode). 一维条码(1D Barcode) 所谓一维条码,简单的说就是条码只能横向水平方向列印,其缺点是储存的资料量较 ...

  2. Linux android studio :'tools.jar' seems to be not in Android Studio classpath.

    问题: 'tools.jar' seems to be not in Android Studio classpath.Please ensure JAVA_HOME points to JDK ra ...

  3. ThinkPHP - 配置项目结构

    配置项目结构: 项目如果分为前后台使用. 那么最关键的就是,使用公共部分文件的划分,其中最为核心的就是公共配置文件的使用. 下面介绍的就是怎么将前后台项目的公共部分提起出来. 首先是其他公共的文件夹: ...

  4. Xcode7网络限制

    在info.plist添加字段 App Transport Security Settings Allow Arbitrary Loads yes

  5. BZOJ 1800 fly-飞行棋

           这道题其实考察的就是从其中能找到几条直径,因为这次数据范围比较小,所以只需设一个二维数组,记录一下每个点及每个点从零开始的位置,最后定一个变量记录周长,最后用个循环搜一下位置小于周长一半 ...

  6. Python 迭代器、生成器、递归、正则表达式 (四)

    一.迭代器&生成器 1.迭代器仅仅是一容器对象,它实现了迭代器协议.它有两个基本方法: 1)next 方法 返回容器的下一个元素 2)_iter_方法 返回迭代器自身.迭代器可以使用内建的it ...

  7. 4.I/O复用以及基于I/O复用的回射客户端/服务器

    I/O复用:当一个或多个I/O条件满足时,我们就被通知到,这种能力被称为I/O复用. 1.I/O复用的相关系统调用 posix的实现提供了select.poll.epoll两类系统调用以及相关的函数来 ...

  8. net core开发环境准备

    net core开发环境准备 1.1  安装sdk和运行时 浏览器打开网址https://www.microsoft.com/net/download, 到.Net Core下载页面. 根据操作系统, ...

  9. springmvc中使用response的out.print问题

    public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws E ...

  10. 46黑名单显示的bug---(优化ListView)convertView复用带来的问题

    是这种需求: 在黑名单的列表中前三个显示特殊的颜色,后面的列表显示其它的颜色,如图: 可是当翻到第二屏的时候.我们发现了: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkb ...