HDU 4708 Rotation Lock Puzzle(数学啊)
来源:互联网 发布:网络备课的好处 编辑:程序博客网 时间:2024/05/08 14:11
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4708
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<cstdio>int minn(int a,int b){ return a<b?a:b;}int main(){ int n; int a[17][17];while(~scanf("%d",&n) && n){int sum = 0, pos = 0;int i, j;int mid = (n+1)/2;for(i = 1; i <= n; i++){for(j = 1; j <= n; j++){scanf("%d",&a[i][j]);if(i==mid && j==mid){sum = a[i][j];}}}int tsum = 0, tpos = 0;for(i = 1; i <= (n-1)/2; i++) //层数{for(j = i; j <= n-i; j++){int tt=(a[j][i]+a[n-j+1][n-i+1])+(a[n-i+1][j]+a[i][n-j+1]); //主副对角线相加if(j==i || tsum<tt){tsum = tt;tpos = minn(j-i,n-(i+j)+1);//逆时针,顺时针}}pos+=tpos;sum+=tsum;}printf("%d %d\n",sum,pos);} 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
- C语言处理图像基本操作1400(读入、拷贝、写出图像及彩色图转灰度图)
- 非小型电子商务系统设计经验分享
- 类对象的复制
- 寻找最小的k个数
- 从零教你如何获取hadoop2.4源码并使用eclipse关联hadoop2.4源码
- HDU 4708 Rotation Lock Puzzle(数学啊)
- linux命令详解之useradd命令使用方法
- Quartus中的unused pin设置
- java里面关于字符串的=号与equals
- Python IDLE reload(sys)后无法正常执行命令的原因
- WCF初步认识
- 微博开启开发者中心——python代码
- 红黑树
- windows中的环境变量