HDU 4708:Rotation Lock Puzzle
来源:互联网 发布:淘宝双11宣传视频 编辑:程序博客网 时间:2024/05/29 21:36
Rotation Lock Puzzle
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1836 Accepted Submission(s): 580
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).
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
59 3 2 5 97 4 7 5 46 9 3 9 35 2 8 7 29 9 4 1 90
Sample Output
72 1
Source
2013 ACM/ICPC Asia Regional Online —— Warmup
迷失在幽谷中的鸟儿,独自飞翔在这偌大的天地间,却不知自己该飞往何方……
题意:给出一个n*n矩阵,n>=3&&n<=9,如果按照最大可能性,只有第二层和第四层有可能是垂直线段覆盖区域!垂直区域可以向逆时针或者顺时针旋转,求旋转几次可以使构成的新矩阵主对角线和副对角线的和最大!
一道简单可暴力解决的题目!因为n<=9!
#include<stdio.h>#include<iostream>using namespace std;int ab[10][10];int tl,tr,bl,br;int main(){ int n; while(~scanf("%d",&n)&&n) { for(int i=1; i<=n; i++) for(int j=1; j<=n; j++) scanf("%d",&ab[i][j]); int add=0,kk=0; for(int i=1; i<=(n-1)/2; i++) { int sum=-0xffffff,ji=0; for(int j=0; j<n-(i*2-1); j++) { tl=ab[i+j][i]; tr=ab[i][n-i+1-j]; bl=ab[n-i+1][i+j]; br=ab[n-i+1-j][n-i+1]; int oth=tl+tr+bl+br; if(oth>sum)sum=oth,ji=j; else if(oth==sum&&j<ji)ji=j; } for(int j=0; j<n-(i*2-1); j++) { tl=ab[i][i+j]; tr=ab[i+j][n-i+1]; bl=ab[n-i+1-j][i]; br=ab[n-i+1][n-i+1-j]; int oth=tl+tr+bl+br; if(oth>sum)sum=oth,ji=j; else if(oth==sum&&j<ji)ji=j; } add+=sum; kk+=ji; } printf("%d %d\n",ab[(n+1)/2][(n+1)/2]+add,kk); } return 0;}
1 0
- 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 4708 Rotation Lock Puzzle(数学啊)
- hdu4708 Rotation Lock Puzzle
- HDU 4708 Rotation Lock Puzzle && 2013 ACM/ICPC Asia Regional Online —— Warmup
- hdu 4708 Rotation Lock Puzzle 2013年ICPC热身赛A题 旋转矩阵
- 2013杭电warm up1 Rotation Lock Puzzle
- STL算法_数值算法篇
- POJ 1523SPF 点双连通分量
- HDU 4707:Pet
- cocoapods 如何正确的上传到SVN
- jQuery对html元素取值与赋值
- HDU 4708:Rotation Lock Puzzle
- 题目1025:最大报销额 学习
- shell时间差计算
- Leetcode 15. 3Sum
- JVM加载机制
- java数组2
- 正则表达式——完美验证
- 笔试题43. LeetCode OJ (30)
- 《啊哈算法》第五章 图的遍历