• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
james1207

博客园    首页    新随笔    联系   管理    订阅  订阅

hdu4708 Rotation Lock Puzzle

Rotation Lock Puzzle

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 654 Accepted Submission(s): 190

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).
 

 

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
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
 

 

Sample Output
72 1
 

 

Source
2013 ACM/ICPC Asia Regional Online —— Warmup
 

 

Recommend
liuyiding
很简单的模拟!
 
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
using namespace std;
int map[12][12];
int main()
{
  int i,j,n,maxx,maxstep,anss,ans;
  while(scanf("%d",&n)!=EOF&&n)
  {
    for(i=0;i<n;i++)
        for(j=0;j<n;j++)
        scanf("%d",&map[i][j]);
    int n2=n/2,temp;
    ans=map[n2][n2];anss=0;
    for(i=0;i<n2;i++)
    {
        int a=0;  int i2=n-i*2;
        maxx=map[i][i+a]+map[i+a][n-i-1]+map[n-i-a-1][i]+map[n-i-1][n-i-1-a];
        maxstep=min(a,i2-1-a);
        for(a=1;a<i2;a++)
        {
            temp=map[i][i+a]+map[i+a][n-i-1]+map[n-i-a-1][i]+map[n-i-1][n-i-1-a];
            if(temp>maxx)
            {
                maxx=temp;
                maxstep=min(a,i2-1-a);
            }
            else if(temp==maxx)
            {
                maxstep=min(maxstep,min(a,i2-1-a));
            }
        }
        ans+=maxx;
        anss+=maxstep;
    }
    printf("%d %d\n",ans,anss);
  }
  return 0;
}


Statistic | Submit | Discuss | Note

 

posted @ 2013-09-10 19:27  Class Xman  阅读(190)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3