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. EFDC主控文件efdc.inp文件的xml格式化处理——转载http://blog.sina.com.cn/s/articlelist_1584892573_0_1.html

    在对EFDC模型进行系统集成时,虽然可以通过一行一行读来进行解析处理,但那将是一个繁琐的工作.我们经过xml格式化处理后,再经xsd转成Dataset类对象,那么整个主控文件就是一个数据库表集合,对其 ...

  2. 关于优化sql查询的一个方法。

    select * from gmvcsbase.base_file file,gmvcsbase.base_user user,gmvcsbase.base_department dep,gmvcsb ...

  3. 【转】 Update和FixedUpdate的区别

    MonoBehaviour.Update 更新 当MonoBehaviour启用时,其Update在每一帧被调用. MonoBehaviour.FixedUpdate 固定更新 当MonoBehavi ...

  4. 低功耗蓝牙4.0BLE编程-nrf51822开发(7)-SDP服务发现协议

    SDP的全称是Service Discovery Protocol,中文是服务发现协议.SDP(服务发现协议)是蓝牙协议体系中的核心协议,是蓝牙系统重要组成部分,是所有用户模式的基础.在蓝牙系统中.客 ...

  5. java项目——数据结构实验报告

    java项目——数据结构总结报告 20135315  宋宸宁 实验要求 1.用java语言实现数据结构中的线性表.哈希表.树.图.队列.堆栈.排序查找算法的类. 2.设计集合框架,使用泛型实现各类. ...

  6. C/C++ 获取汉字拼音

    参考文章:http://blog.csdn.net/thenile/article/details/6318521 在参考文章的基础上,去掉了代码中C++特有的语法和数据类型,用纯C语言实现了获取汉字 ...

  7. IE中的fireEvent和webkit中的dispatchEvent

    拿浏览器的click事件来说: 在IE浏览器中如果一个element没有注册click事件,那么直接调用的话会出现异常!当然如果你注册了没有什么可说的. 那么如果使用fireEvent来处理,clic ...

  8. ArcGIS Engine开发之旅01---产品组成、逻辑体系结构

    原文:ArcGIS Engine开发之旅01---产品组成.逻辑体系结构 ArcGIS Engine 由两个产品组成:  面向开发人员的软件开发包(ArcGIS Engine Developer k ...

  9. Select Statement Syntax [AX 2012]

    Applies To: Microsoft Dynamics AX 2012 R3, Microsoft Dynamics AX 2012 R2, Microsoft Dynamics AX 2012 ...

  10. dedecms程序给栏目增加缩略图的方法

    用织梦程序做网站,有时候因为功能需求,我们要为网站的栏目页添加缩略图功能,而dedecms又没自带这个功能,那么就需要我们来修改程序了. 这里有一个栏目添加缩略图的方法,供大家参考. 涉及到文件如下( ...