Rotation Lock Puzzle

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

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
 

按照题目意思去旋转。

求最大值

 /* *******************************************
Author : kuangbin
Created Time : 2013年09月08日 星期日 12时33分12秒
File Name : 1003.cpp
******************************************* */ #include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string.h>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std; long long a[][];
int n;
void change(int &x,int &y,int k)
{
if(x == k)
{
if(y == k)
{
x++;
}
else y--;
}
else if(x == n+-k)
{
if(y == n+-k)
x--;
else y++;
}
else if(y == k)
x++;
else x--;
}
int main()
{
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
while(scanf("%d",&n) && n)
{
for(int i = ;i <= n;i++)
for(int j = ;j <= n;j++)
cin>>a[i][j];
long long ans1 = , ans2 = ;
for(int i = ;i <= n/;i++)
{
int x0 = i,y0 = i;
int x1 = i,y1 = n+-i;
int x2 = n+-i,y2 = i;
int x3 = n+-i,y3 = n+-i;
int tmp1 = a[x0][y0] + a[x1][y1] + a[x2][y2] + a[x3][y3];
int tmp2 = ;
for(int j = ;j < (n+-*i-);j++)
{
change(x0,y0,i);
change(x1,y1,i);
change(x2,y2,i);
change(x3,y3,i);
int tt = min(j+,n+-*i--(j+));
if(tmp1 < a[x0][y0] + a[x1][y1] + a[x2][y2] + a[x3][y3])
{
tmp1 = a[x0][y0] + a[x1][y1] + a[x2][y2] + a[x3][y3];
tmp2 = tt;
}
else if(tmp1 == a[x0][y0] + a[x1][y1] + a[x2][y2] + a[x3][y3] && tmp2 > tt)
{
tmp2 = tt;
}
}
ans1 += tmp1;
ans2 += tmp2;
}
ans1 += a[n/+][n/+];
cout<<ans1<<" "<<ans2<<endl;
}
return ;
}

HDU 4708 Rotation Lock Puzzle (简单题)的更多相关文章

  1. HDU 4708:Rotation Lock Puzzle

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

  2. HDU 4708 Rotation Lock Puzzle(模拟)

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

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

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

  4. 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 ...

  5. hdu4708 Rotation Lock Puzzle

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

  6. HDUOJ---(4708)Rotation Lock Puzzle

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

  7. HDU 2802 F(N)(简单题,找循环解)

    题目链接 F(N) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...

  8. Rotation Lock Puzzle

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

  9. HDOJ(HDU) 2123 An easy problem(简单题...)

    Problem Description In this problem you need to make a multiply table of N * N ,just like the sample ...

随机推荐

  1. Linux 获取网关地址

    route命令的用法:操作或者显示IP路由表route:DESCRIPTION Route manipulates the kernel's IP routing tables. Its primar ...

  2. 试用Redis

    Windows 10家庭中文版,运行于VirtualBox上的Ubuntu 18.04,Redis 4.0.10, Redis,久仰大名!因为没有从事互联网行业,所以一直没有使用过.近期找工作,也隐约 ...

  3. java基础78 Servlet的生命周期

    1.Servlet的生命周期 简单的解析就是: 创建servlet实例(调用构造器)---->调用init()方法---->调用service()方法----->调用destroy( ...

  4. 不同Linux机器之间拷贝文件

    不同的Linux之间copy文件常用有3种方法: 第一种就是ftp,也就是其中一台Linux安装ftp Server,这样可以另外一台使用ftp的client程序来进行文件的copy. 第二种方法就是 ...

  5. No.1 selenium学习之路之浏览器操作

    selenium基础,首先就是浏览器的相关操作 下面描述几种浏览器的常用操作 1.打开浏览器 webdriver后面添加想要打开的浏览器 Ie或者Chrome 2.打开指定页面(百度) 3.休眠时间 ...

  6. MySQL通过rpm安装及其单机多实例部署

    1. CentOS 下安装 MySQL Oracle 收购 MySQL 后,CentOS 为避免 MySQL 闭源的风险,改用 MySQL 的分支 MariaDB:MariaDB 完全兼容 MySQL ...

  7. Java MongoDB : Save image example

    In this tutorial, we show you how to save an image file into MongoDB, via GridFS API. The GridFS API ...

  8. XeLaTeX下如何以原大小显示PNG

    在XeLaTeX里直接使用\includegraphics{test.png}这样的命令引入PNG,可能会发现图片直接被缩放到占满文档宽度,这是因为PNG这种bitmap类型的图片里通常不会带上met ...

  9. IEEEXtreme 极限编程大赛题解

    这是 meelo 原创的 IEEEXtreme极限编程大赛题解 IEEEXtreme全球极限编程挑战赛,是由IEEE主办,IEEE学生分会组织承办.IEEE会员参与指导和监督的.IEEE学生会员以团队 ...

  10. 【Java】 用PriorityQueue实现最大最小堆

    PriorityQueue(优先队列),一个基于优先级堆的无界优先级队列. 实际上是一个堆(不指定Comparator时默认为最小堆),通过传入自定义的Comparator函数可以实现大顶堆. Pri ...