hdu 4708 Rotation Lock Puzzle
来源:互联网 发布:人工智能聊天app 编辑:程序博客网 时间:2024/05/29 16:28
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
#include<iostream>#include<stdio.h>#include<string.h>using namespace std;int ma[16][16];int sum[10][10];//从中间起第i圈分为j个组,这j个组的和int q[12]= {0,1,2,3,4,5,6,7,8,9,10,11}; //从中间向外扩int main(){ int n; int i,j; int t; int k; int ma_sum,ma_loc; int tol_sum; int tol_step; while(~scanf("%d",&n)) { if(n==0) { break; } for(i=0; i<n; ++i) { for(j=0; j<n; ++j) { scanf("%d",&ma[i][j]); } } t=n/2; memset(sum,0,sizeof(sum)); tol_sum=0; tol_step=0; for(i=0; i<t; ++i) { ma_sum=0; for(j=0; j<(i+1)*2; ++j) { sum[i][j]=ma[t-i-1+q[j]][t-i-1]+ma[t+i+1][t-i-1+q[j]]+ma[t+i+1-q[j]][t+i+1]+ma[t-i-1][t+i+1-q[j]]; // cout<<ma[t-i-1+q[j]][t-i-1]<<" "<<ma[t+i+1][t-i-1+q[j]]<<" "<<ma[t+i+1-q[j]][t+i+1]<<" "<<ma[t-i-1][t+i+1-q[j]]<<endl; if(sum[i][j]>ma_sum) { ma_sum=sum[i][j]; ma_loc=j; } } if(ma_loc-0<(i+1)*2-ma_loc) { tol_step+=ma_loc; } else { tol_step+=(i+1)*2-ma_loc; } tol_sum+=ma_sum; } printf("%d %d\n",tol_sum+ma[t][t],tol_step); } return 0;}
0 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
- UVALive 7009 Secret Binary Tree(二分查找、dfs)
- 如何用Notepad++运行Python脚本
- 编译Apache问题
- 包装类转化、正则表达式
- laravel5分钟完成登录注册
- hdu 4708 Rotation Lock Puzzle
- 图解Ollydbg简单逆向操作案例
- 链表(实现增删查改)
- RxJava-操作符 初步学习
- 【17】-冒泡排序详解
- 整合Kafka到Spark Streaming——代码示例和挑战
- android打开系统程序
- Java-多线程
- 【Stanford机器学习笔记】6-Neural Networks: Representation