Rotation Lock Puzzle

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

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
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<queue>
#include<algorithm>
#include<iomanip>
#define INF 99999999
using namespace std; const int MAX=10;
int s[MAX][MAX]; int main(){
int n;
while(scanf("%d",&n),n){
for(int i=0;i<n;++i){
for(int j=0;j<n;++j)scanf("%d",&s[i][j]);
}
int sum=0,num=0,temp=0,k;
for(int i=0;i<n/2;++i){//从第i行开始的四边形
k=0,temp=-INF;
for(int j=0;j<=n-2*i-2;++j){//分别计算顺时针旋转j(逆时针旋转n-2*i-1-j次)次后左上角,左下角,右上角,右下角相加的和
if(s[i+j][i]+s[n-1-i][i+j]+s[i][n-1-i-j]+s[n-1-i-j][n-1-i]>temp){
temp=s[i+j][i]+s[n-1-i][i+j]+s[i][n-1-i-j]+s[n-1-i-j][n-1-i];
k=j;
}
}
sum+=temp;
num+=min(k,n-2*i-1-k);
}
cout<<sum+s[n/2][n/2]<<' '<<num<<endl;
}
return 0;
}

hdu4708的更多相关文章

  1. hdu4708 Rotation Lock Puzzle

    Rotation Lock Puzzle Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...

随机推荐

  1. iOS UILabel 使用姿势大全(标红关键字)

    一.初始化 ? 1 2 3 UILabel *myLabel = [[UILabel alloc] initWithFrame:CGRectMake(40, 40, 120, 44)];       ...

  2. UIViewController XIB/NIB加载过程

    UIViewController中关于nib初始化的函数 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBu ...

  3. 【论文阅读】Retrieving Similar Similar Styles to Parse Clothing(相关工作)

    发表于2015年5月PAMI 作者: Kota Yamaguchi, M.Hadi Kiapour, Luis E. Ortiz, Tamara L. Berg 相关工作: [服装检索Clothing ...

  4. 仿爱乐透android客户端界面实现(附工程源码)

    最近研究了爱乐透android客户端的界面,感觉它的界面布局在一般开发中具有代表性.难点在于复杂的布局实现. 界面实现主要采用了以下方式: 注意:版本支持:android2.2以上,低版本要改动源码哦 ...

  5. Linux 开放服务端口

    CentOS 6.5上安装Tomcat 服务器,需要开放服务端口,供其他计算机访问部署在Tomcat中的Web应用.下面是开放端口的方法. 我知道的方法有两种.下面以开放8080端口为例. 方法一:命 ...

  6. CodeForces 294B Shaass and Bookshelf 【规律 & 模拟】或【Dp】

    这道题目的意思就是排两排书,下面这排只能竖着放,上面这排可以平着放,使得宽度最小 根据题意可以得出一个结论,放上这排书的Width 肯定会遵照从小到大的顺序放上去的 Because the total ...

  7. zoj 2277 The Gate to Freedom

    N^N = X --->    Nlog10(N) = log10( X ) ---->    X的最高位为 Nlog10(N) 小数部分的第一个非0位 #include<stdio ...

  8. iframe,window,滚动栏的一些问题

    1.Iframe不显示边框:frameborder=0 2.Iframe不显示横向滚动栏:在iframe所指向的页面增加: <style> html{overflow-x:hidden;} ...

  9. Android实现 再按一次退出 的三种方法 durationTime、timerTask 和Handler

    目前很多Android应用都会实现按返回键时提示“再按一次推退出” 在这篇文章中总结了各家的方法,一般都是监听Activity的onKeyDown 或者onBackPressed方法 方法一: 直接计 ...

  10. Android Bluetooth开发

    原文地址:http://developer.android.com/guide/topics/wireless/bluetooth.html 翻译:jykenan 更新:2012.06.19 Andr ...