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. 深入浅出—JAVA(6)

    6.认识JAVA的API Arraylist的操作

  2. Spring读书笔记-----部署我的第一个Spring项目

    一.Spring介绍 Spring是一个轻量级的Java EE容器,它也是一种从实际需求出发,着眼于轻便,灵活,易于开发,易测试和易部署的轻量级开发框架.Spring它完成了大量开发中的通用步骤,留给 ...

  3. C++堆和栈的比较(7个区别)

    基础知识: 堆 栈是一种简单的数据结构,是一种只允许在其一端进行插入或删除的线性表.允许插入或删除操作的一端称为栈顶,另一端称为栈底,对堆栈的插入和删除操作被称 为入栈和出栈.有一组CPU指令可以实现 ...

  4. page分页

    首先封装一个分页类 public class Page<T> { /** * 当前页号 */ private int pageNumber; /** * 总条数 */ private in ...

  5. 移植FreeModbus+ModbusMaster+STM32至RT-Thread(3、4阶段)

    一.简介及进展 经过一个多月的努力,目前项目开发已进入最后阶段.虽然比预期时间有些延迟,但也收获不少,边工作边开源的效率确实还有待提高. 简单说下目前的进展吧 1.目前项目已经在Github中开源,大 ...

  6. JDBC批量运行executeBatch

    JDBC运行SQL语句,有两个处理的接口,一个PreparedStatement,Statement,一般操作JDBC比較用得多的还是PreparedStatement 只是在运行批量,Prepare ...

  7. 跟我一起学extjs5(25--模块Form的自己定义的设计[3])

    跟我一起学extjs5(25--模块Form的自己定义的设计[3])         自己定义的Form已经能够执行了,以下改一下配置,把Form里面的FieldSet放在Tab之下.改动一下Modu ...

  8. MSSQLServer的备份与还原

    最近用到了mssql2000的数据备份还原到2008上, 在备份2000时,一定注意要备份成一个文件,就是目标那里只添加一个就好,(否则待会还原数据库时要添加这两个文件,要不就报“备份了几个簇,只提供 ...

  9. UIAlertView、UIActionSheet兼容iOS8

    链接地址:http://blog.csdn.net/nextstudio/article/details/39959895?utm_source=tuicool 1.前言 iOS8新增了UIAlert ...

  10. [转]Windows7 64bit下配置Apache+PHP+MySQL

    原文链接:http://blog.csdn.net/sbz0409/article/details/12946375 1.准备资料: 首先下载文件:Apache2.4.16 64bit,http:// ...