Rotation Lock Puzzle
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).
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
#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn=;
const int maxm= + ; int n, M[maxn][maxn];
int d[maxn][maxm]; //d[i][j]表示从外往里数第i层,从左上角开始,下标从0开始,顺时针第j个是谁
int Max[maxn]; //Max[i]表示第i层对角线的4个数的和的最大值
int r[maxn]; //r[i]表示第i层转到对角线的4个数的和的最大值时转了多少次 void read()
{
int i,j;
for(i= ; i<n; i++)
for(j=; j<n; j++)
scanf("%d", &M[i][j]);
} void get_d()
{
int i,j,m;
for(i= ; i<n/; i++)
{
m=;
for(j=i; j<n-i; j++) d[i][m++]=M[i][j];
for(j=i+; j<n-i; j++) d[i][m++]=M[j][n--i];
for(j=n--i; j>=i; j--) d[i][m++]=M[n--i][j];
for(j=n--i; j>i; j--) d[i][m++]=M[j][i];
}
} void get_Mr()
{
int i,j;
for(i= ; i<n/; i++)
{
int N=(n - i*) -;
int Ma=-;
for(j=; j<N; j++) //转j次
{
int temp=d[i][j] + d[i][j+N] + d[i][j+*N] + d[i][j+*N];
if(temp>Ma)
{
Ma=temp;
Max[i]=temp;
r[i]=min(j, N-j);
}
else if(temp == Ma)
{
r[i]=min(r[i], j);
r[i]=min(r[i], N-j);
}
}
}
} void solve()
{
int sum_val=, sum_rot=,i;
for(i= ; i<n/; i++) sum_val += Max[i];
sum_val += M[n/][n/];
for(i= ; i<n/; i++) sum_rot += r[i];
printf("%d %d\n", sum_val, sum_rot);
} int main()
{
while(scanf("%d", &n) == && n)
{
read();
get_d();
get_Mr();
solve();
}
return ;
}
Rotation Lock Puzzle的更多相关文章
- 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 ...
- HDU 4708:Rotation Lock Puzzle
Rotation Lock Puzzle Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- hdu4708 Rotation Lock Puzzle
Rotation Lock Puzzle Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- HDU 4708 Rotation Lock Puzzle (简单题)
Rotation Lock Puzzle Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- HDUOJ---(4708)Rotation Lock Puzzle
Rotation Lock Puzzle Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- HDU 4708 Rotation Lock Puzzle(模拟)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4708 题目大意:给定一个方形矩阵,边长为3-10的奇数.每一圈的数字可以沿着顺时针方向和逆时针方向旋转 ...
- hdu 4708 Rotation Lock Puzzle 2013年ICPC热身赛A题 旋转矩阵
题意:给出一个n*n的矩阵,旋转每一圈数字,求出对角线可能的最大值,以及转到最大时的最小距离. 只要分析每一层就可以了,本来想用地址传递二维数组,发现行不通,改了一下就行了. 这里有个坑,比如: 1 ...
- Codeforces Round #467 (Div. 2) E -Lock Puzzle
Lock Puzzle 题目大意:给你两个字符串一个s,一个t,长度<=2000,要求你进行小于等于6100次的shift操作,将s变成t, shift(x)表示将字符串的最后x个字符翻转后放到 ...
- Codeforces Round #467 (Div. 1). C - Lock Puzzle
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> ...
随机推荐
- Initializer block.
Ref: Initializing Fields Instance initializers are permitted to refer to the current object via the ...
- Kettle 实现mysql数据库不同表之间数据同步——实验过程
下面是试验的主要步骤: 在上一篇文章中LZ已经介绍了,实验的环境和实验目的. 在本篇文章中主要介绍侧重于对Kettle ETL的相应使用方法, 在这里LZ需要说明一下,LZ成为了避免涉及索引和表连接等 ...
- Netbeans IDE配置
- GoogleAuthenticator
<?php /** * PHP Class for handling Google Authenticator 2-factor authentication * * @author Micha ...
- css 不确定元素宽度的水平居中
对于一个不确定宽度的元素居中,我们想到使用的方法是 text-align:center; 或者 margin:0 auto; text-align只对行内元素有效,对于块元素我们要用margin,块元 ...
- SQL2012之FileTable与C#的联合应用
关于FileTable是什么,请猛击如下链接:http://technet.microsoft.com/zh-cn/library/ff929144(v=SQL.110).aspx:如您已知道,请跳过 ...
- Bootstrap_表单_图标
在Bootstrap框架中是通过给元素添加“glyphicon”类名来实现,然后通过伪元素“:before”的“content”属性调取对应的icon编码: <span class=" ...
- php之框架增加日志记录功能类
<?php /* 思路:给定文件,写入读取(fopen ,fwrite……) 如果大于1M 则重写备份 传给一个内容, 判断大小,如果大于1M,备份 小于则写入 */ class Log{ // ...
- Tornado 的教材
Tornado 的教材 作者:杨昆链接:https://www.zhihu.com/question/19707966/answer/12731684来源:知乎著作权归作者所有,转载请联系作者获得授权 ...
- mysql的SQL_CALC_FOUND_ROWS 使用
mysql的SQL_CALC_FOUND_ROWS 使用 标签: sqlmysqltable 2007-02-27 11:40 5073人阅读 评论(0) 收藏 举报 分类: Mysql数据库技术( ...