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. mybatis 控制台打印sql脚本

    在mybatis-config.xml文件中加一句 <setting name="logImpl" value="STDOUT_LOGGING" /> ...

  2. CSS--盒子模型详解

    目录 图解 盒模型尺寸基准 使用浏览器的开发者工具,查看元素高(宽)度时,遇到的问题 一.图解 说明:由内而外依次是content.padding(内边距).border(边框).margin(外边距 ...

  3. POJ 1236 Network of Schools(tarjan求强连通分量+思维)

    题目链接:http://poj.org/problem?id=1236 题目大意: 给你一个网络(有向图),有两个任务: ①求出至少同时需要几份副本可以使得整个网络都获得副本 ②至少添加多少信息表(有 ...

  4. MySQL学习笔记:coalesce

    函数:coalesce 作用:返回传入的参数中第一个非NULL的值 ); # ); # 如果传入的参数所有都是NULL,则返回NULL,比如: SELECT COALESCE(NULL, NULL, ...

  5. Windbg在应用层调试漏洞时的应用

    主要记录一些在应用层调试漏洞的技巧,不会写一些基本的命令,只记录比较有用的平时难以想到的调试方法. 1.!address eax 查看对应内存页的属性,如果poc触发异常之后就可以用这个指令看一下触发 ...

  6. XML&反射

    本节内容: XML DTD约束 Schema约束 dom4j解析 反射 为了实现访问不同路径(/hello)执行不同的资源(HelloMyServlet),我们需要使用XML进行配置:为了限定XML内 ...

  7. 【PAT】1017 A除以B(20 分)

    1017 A除以B(20 分) 本题要求计算 A/B,其中 A 是不超过 1000 位的正整数,B 是 1 位正整数.你需要输出商数 Q 和余数 R,使得 A=B×Q+R 成立. 输入格式: 输入在一 ...

  8. 【51nod】1559 车和矩形

    题解 离线读入,我们发现一个矩形能被保护,矩形内部所有列上必定有一辆车,或者所有行上必定有一辆车 分两次进行处理 第一次按照横坐标把车加进去,然后查询最大横坐标在这个位置的矩形,纵坐标区间里的车出现位 ...

  9. shell变量定义中的特殊符号

    今天要写一个shell语句来输出数据库的v$database的信息 定义bb为一个接收sql返回值的变量 需要注意的是: select * from v$database ;  语句 由于其中用到了$ ...

  10. 002 python语法入门

    一:基本数据类型知识点 1.基本数据类型 Number 数字 String 字符串 Bool 布尔 List 列表 Tuple 元组 Set 集合 Dictionary字典 2.分类 )标准的pyth ...