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代码:

 #include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
long long a[][];
long long step,ans;
void solve1(int t,int x1,int y1,int x2,int y2,int x3,int y3,int x4,int y4)
{
int i;
long long w;
t = t-;
for(i=;i<t;i++)
{
w = a[x1][y1] + a[x2][y2]+a[x3][y3]+a[x4][y4];
y1++;
x2++;
y3--;
x4--;
if(w>ans)
{
ans = w;
step = i;
}
}
}
void solve2(int t,int x1,int y1,int x2,int y2,int x3,int y3,int x4,int y4)
{
int i;
t =t-;
long long w;
//printf("ans = %d %d\n",ans,step);
for(i=;i<t;i++)
{
w = a[x1][y1] + a[x2][y2]+a[x3][y3]+a[x4][y4];
x1++;
y2--;
x3--;
y4++;
if(w>=ans)
{
ans = w;
if(step>i)
step=i;
}
}
}
int main()
{
int T;
long long ss,aa;
while(scanf("%d",&T) && T)
{
ss = ;aa = ;
for(int i=;i<=T;i++)
for(int j=;j<=T;j++)
scanf("%lld",&a[i][j]);
int mid1 = (T+)/;
for(int i=,k=;i<=T;i=i+,k++)
{
step = ;ans = ;
solve1(i,mid1 - k,mid1-k,mid1-k,mid1+k,mid1+k,mid1+k,mid1+k,mid1-k);
solve2(i,mid1 - k,mid1-k,mid1-k,mid1+k,mid1+k,mid1+k,mid1+k,mid1-k);
ss= ss +step;
aa = ans+aa;
}
printf("%lld %lld\n",aa+a[mid1][mid1],ss);
}
return ;
}

hduoj 4708 Rotation Lock Puzzle 2013 ACM/ICPC Asia Regional Online —— Warmup的更多相关文章

  1. hduoj 4715 Difference Between Primes 2013 ACM/ICPC Asia Regional Online —— Warmup

    http://acm.hdu.edu.cn/showproblem.php?pid=4715 Difference Between Primes Time Limit: 2000/1000 MS (J ...

  2. hduoj 4706 Herding 2013 ACM/ICPC Asia Regional Online —— Warmup

    hduoj 4706 Children's Day 2013 ACM/ICPC Asia Regional Online —— Warmup Herding Time Limit: 2000/1000 ...

  3. hduoj 4712 Hamming Distance 2013 ACM/ICPC Asia Regional Online —— Warmup

    http://acm.hdu.edu.cn/showproblem.php?pid=4712 Hamming Distance Time Limit: 6000/3000 MS (Java/Other ...

  4. hduoj 4710 Balls Rearrangement 2013 ACM/ICPC Asia Regional Online —— Warmup

    http://acm.hdu.edu.cn/showproblem.php?pid=4710 Balls Rearrangement Time Limit: 6000/3000 MS (Java/Ot ...

  5. hduoj 4707 Pet 2013 ACM/ICPC Asia Regional Online —— Warmup

    http://acm.hdu.edu.cn/showproblem.php?pid=4707 Pet Time Limit: 4000/2000 MS (Java/Others)    Memory ...

  6. hduoj 4706 Children&#39;s Day 2013 ACM/ICPC Asia Regional Online —— Warmup

    http://acm.hdu.edu.cn/showproblem.php?pid=4706 Children's Day Time Limit: 2000/1000 MS (Java/Others) ...

  7. 2013 ACM/ICPC Asia Regional Online —— Warmup

    1003 Rotation Lock Puzzle 找出每一圈中的最大值即可 代码如下: #include<iostream> #include<stdio.h> #inclu ...

  8. hdu 4708 Rotation Lock Puzzle 2013年ICPC热身赛A题 旋转矩阵

    题意:给出一个n*n的矩阵,旋转每一圈数字,求出对角线可能的最大值,以及转到最大时的最小距离. 只要分析每一层就可以了,本来想用地址传递二维数组,发现行不通,改了一下就行了. 这里有个坑,比如: 1 ...

  9. HDU 4714 Tree2cycle(树状DP)(2013 ACM/ICPC Asia Regional Online ―― Warmup)

    Description A tree with N nodes and N-1 edges is given. To connect or disconnect one edge, we need 1 ...

随机推荐

  1. C++位操作符总结

    #include <stdio.h> #include <memory.h> #include <malloc.h> #define MaxBinLength 16 ...

  2. xcode5 和code6中push后方法执行的先后问题

    在xocde5中 执行的顺序是 prepareForSegue  .viewDidLoad. didSelectRowAtIndexPath,在xcode6中 执行的顺序是  prepareForSe ...

  3. Magento PDF发票,支持中文,以及修改的办法

    Magento PDF发票,支持中文,以及修改的办法.   如果让magento的PDF发票支持中文.Magento生成PDF发票.使用的是zend framework的zend_pdf类. 下面是一 ...

  4. JMeter学习-016-思路篇之-山重水复柳暗花明

    首先,此文非技术类博文,为思路类的博文,敬请参阅,欢迎共同探讨! 今天在编写 JMeter 接口监控脚本时,遇到了一个问题,在解决问题的时候,思路出现了偏差,导致了自己在解决问题时,绕了弯,浪费了些时 ...

  5. JMeter学习-008-JMeter 后置处理器实例之 - 正则表达式提取器(一)概述及简单实例

    上文我们讲述了如何对 HTTP请求 的响应数据进行断言,以判断响应是否符合我们的预期,敬请参阅:JMeter学习-007-JMeter 断言实例之一 - 响应断言 那么我们如何获取 HTTP请求 响应 ...

  6. windows7 密码保护 共享文件

    windows7 密码保护 共享文件 2台windows7之间设置文件共享,本想使用ftp,但是配置指定用户连接,配置权限比较繁琐. 所以就想到使用window7的文件共享,并设置密码,共享整个硬盘的 ...

  7. iOS 使用XCode6打开项目以后再用XCode5出现的问题fatal error: malformed or corrupted AST file: 'Unable to load module

    使用不同版本的XCode出现的问题: fatal error: malformed or corrupted AST file: 'Unable to load module "/Users ...

  8. flex box 布局

    .box{ display:flex; } .box { display: inline-flex; } .box { display:-webkit-flex; display: flex; } f ...

  9. 源码搭建SVN+Apache+Setpass

    1.安装配置apache2.2.18 http://download.csdn.net/download/YH555/3299526tar xf httpd-2.2.18.tar.bz2cd http ...

  10. mysql怎么终止当前正在执行的sql语句

    mysql怎么终止当前正在执行的sql语句 show processlist; kill 要杀的ID kill 7