hdu 4708 Rotation Lock Puzzle 2013年ICPC热身赛A题 旋转矩阵
来源:互联网 发布:linux shell 数值计算 编辑:程序博客网 时间:2024/05/30 07:12
题意:给出一个n*n的矩阵,旋转每一圈数字,求出对角线可能的最大值,以及转到最大时的最小距离。
只要分析每一层就可以了,本来想用地址传递二维数组,发现行不通,改了一下就行了。
这里有个坑,比如:
1 1 9 9 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
很明显最大的就是将一个9转到矩阵角,而这里更新最大值时很容易把另一种情况屏蔽掉,从而错过了更少步骤达到最大值的方法。
代码:
/** Author: illuz <iilluzen[at]gmail.com>* Blog: http://blog.csdn.net/hcbbt* File: 3.cpp* Create Date: 2013-09-08 14:21:58* Descripton: simulate */#include <cstdio>#include <algorithm>using namespace std;#define rep(i, n) for (int i = 0; i < (n); i++)const int MAXN = 100;int a[MAXN][MAXN];int n, sum, cnt;void solve(int k, int l) {int tmp = -0xffffff, tt = 0;rep(i, l - 1) {int t = a[k][k + i] + a[k + i][k + l - 1] + a[k + l - i - 1][k + 0] + a[k + l - 1][k + l - i - 1];if (tmp <= t) {if (tmp == t)tt = min(tt, min(i, l - i - 1));elsett = min(i, l - i - 1);tmp = t;}}sum += tmp;cnt += tt;}int main() {while (scanf("%d", &n) && n) {rep(i, n) rep(j, n)scanf("%d", &a[i][j]);int l = n / 2;sum = a[l][l];cnt = 0;rep(i, l)solve(i, n - 2 * i);printf("%d %d\n", sum, cnt);}return 0;}
- hdu 4708 Rotation Lock Puzzle 2013年ICPC热身赛A题 旋转矩阵
- HDU 4708 Rotation Lock Puzzle (热身赛第三题)
- HDU 4708 Rotation Lock Puzzle && 2013 ACM/ICPC Asia Regional Online —— Warmup
- hdu - 4708 - Rotation Lock Puzzle
- hdu 4708 Rotation Lock Puzzle
- HDU 4708 Rotation Lock Puzzle
- hdu 4708 Rotation Lock Puzzle
- HDU 4708 Rotation Lock Puzzle
- HDU 4708 Rotation Lock Puzzle
- HDU 4708 Rotation Lock Puzzle
- hdu 4708 Rotation Lock Puzzle
- HDU 4708:Rotation Lock Puzzle
- hdu 4708 Rotation Lock Puzzle(模拟)
- HDU 4708 Rotation Lock Puzzle 解题报告
- Hdu 4708 Rotation Lock Puzzle --模拟
- HDU 4708 Rotation Lock Puzzle(数学啊)
- hdu 4715 Difference Between Primes 2013年ICPC热身赛A题 素数水题
- hdu 4706 Children's Day 2013年ICPC热身赛A题 模拟
- GC策略笔记备忘(被namenode所迫)
- static关键字
- poj 2533 数组的最长上升子序列
- paxos算法
- HDU 4067 Random Maze 最小费用最大流
- hdu 4708 Rotation Lock Puzzle 2013年ICPC热身赛A题 旋转矩阵
- ExcelSheetHelperTest
- Viewstamps算法
- 短信监听器
- Chord算法(原理)
- after《很高兴见到你》
- javascript的history.back()兼容性问题
- PMBOK学习笔记-项目管理、项目集管理和项目组合管理间的关系
- 满足min.push.pop操作时间复杂度为o(1)的栈