zoukankan      html  css  js  c++  java
  • hduoj 4708 Rotation Lock Puzzle 2013 ACM/ICPC Asia Regional Online —— Warmup

    http://acm.hdu.edu.cn/showproblem.php?pid=4708

    Rotation Lock Puzzle

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

    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

    分析:

    题意是求将水平阴影或者竖直阴影旋转最小的次数和,使得主对角线与副对角线的代数和最大。

    直接模拟即可。

    AC代码:

     1 #include<iostream>
     2 #include<algorithm>
     3 #include<cstdio>
     4 using namespace std;
     5 long long  a[15][15];
     6 long long step,ans;
     7 void solve1(int t,int x1,int y1,int x2,int y2,int x3,int y3,int x4,int y4)
     8 {
     9     int i;
    10     long long w;
    11     t = t-1;
    12     for(i=0;i<t;i++)
    13     {
    14         w = a[x1][y1] + a[x2][y2]+a[x3][y3]+a[x4][y4];
    15         y1++;
    16         x2++;
    17         y3--;
    18         x4--;
    19             if(w>ans)
    20             {
    21              ans = w;
    22              step = i;
    23             }
    24      }
    25 }
    26 void solve2(int t,int x1,int y1,int x2,int y2,int x3,int y3,int x4,int y4)
    27 {
    28     int i;
    29     t =t-1;
    30     long long w;
    31     //printf("ans = %d %d
    ",ans,step);
    32     for(i=0;i<t;i++)
    33     {
    34         w = a[x1][y1] + a[x2][y2]+a[x3][y3]+a[x4][y4];
    35         x1++;
    36         y2--;
    37         x3--;
    38         y4++;
    39             if(w>=ans)
    40             {
    41               ans = w;
    42               if(step>i)
    43                  step=i;
    44             }
    45      }
    46 }
    47 int main()
    48 {
    49     int T;
    50     long long ss,aa;
    51     while(scanf("%d",&T) && T)
    52     {
    53         ss = 0;aa = 0;
    54         for(int i=1;i<=T;i++)
    55             for(int j=1;j<=T;j++)
    56                scanf("%lld",&a[i][j]);
    57         int mid1 = (T+1)/2;
    58         for(int i=3,k=1;i<=T;i=i+2,k++)
    59         {
    60             step = 0;ans = 0;
    61             solve1(i,mid1 - k,mid1-k,mid1-k,mid1+k,mid1+k,mid1+k,mid1+k,mid1-k);
    62             solve2(i,mid1 - k,mid1-k,mid1-k,mid1+k,mid1+k,mid1+k,mid1+k,mid1-k);
    63             ss= ss +step;
    64             aa = ans+aa;
    65         }
    66    printf("%lld %lld
    ",aa+a[mid1][mid1],ss);
    67     }
    68     return 0;
    69 }
    View Code
  • 相关阅读:
    strpos 判断字符串是否存在
    TP 自动验证
    label 标签的用法,点label选中单选、复选框或文本框
    str_replace 替换 小技巧
    数据库文件MDF的空间占满了,没有自动增长是怎么回事?
    (4.7)mysql备份还原——深入解析二进制日志(3)binlog的三种日志记录模式详解
    (4.6)mysql备份还原——深入解析二进制日志(2)binlog参数配置解析
    (1.16)mysql server优化之buffer pool
    COALESCE函数
    linux网络设置和虚拟机克隆转移之后网卡找不到
  • 原文地址:https://www.cnblogs.com/jeff-wgc/p/4467506.html
Copyright © 2011-2022 走看看