首页 技术 正文
技术 2022年11月16日
0 收藏 486 点赞 4,856 浏览 2444 个字

Rotation Lock Puzzle

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

Problem DescriptionAlice 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.

HDU 4708 Rotation Lock Puzzle (简单题)

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

 InputMulti 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 . OutputFor each test case, output the maximum sum of two diagonals and minimum steps to reach this target in one line. Sample Input5
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 Output72 1 Source2013 ACM/ICPC Asia Regional Online —— Warmup Recommendliuyiding 

按照题目意思去旋转。

求最大值

 /* *******************************************
Author : kuangbin
Created Time : 2013年09月08日 星期日 12时33分12秒
File Name : 1003.cpp
******************************************* */ #include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string.h>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std; long long a[][];
int n;
void change(int &x,int &y,int k)
{
if(x == k)
{
if(y == k)
{
x++;
}
else y--;
}
else if(x == n+-k)
{
if(y == n+-k)
x--;
else y++;
}
else if(y == k)
x++;
else x--;
}
int main()
{
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
while(scanf("%d",&n) && n)
{
for(int i = ;i <= n;i++)
for(int j = ;j <= n;j++)
cin>>a[i][j];
long long ans1 = , ans2 = ;
for(int i = ;i <= n/;i++)
{
int x0 = i,y0 = i;
int x1 = i,y1 = n+-i;
int x2 = n+-i,y2 = i;
int x3 = n+-i,y3 = n+-i;
int tmp1 = a[x0][y0] + a[x1][y1] + a[x2][y2] + a[x3][y3];
int tmp2 = ;
for(int j = ;j < (n+-*i-);j++)
{
change(x0,y0,i);
change(x1,y1,i);
change(x2,y2,i);
change(x3,y3,i);
int tt = min(j+,n+-*i--(j+));
if(tmp1 < a[x0][y0] + a[x1][y1] + a[x2][y2] + a[x3][y3])
{
tmp1 = a[x0][y0] + a[x1][y1] + a[x2][y2] + a[x3][y3];
tmp2 = tt;
}
else if(tmp1 == a[x0][y0] + a[x1][y1] + a[x2][y2] + a[x3][y3] && tmp2 > tt)
{
tmp2 = tt;
}
}
ans1 += tmp1;
ans2 += tmp2;
}
ans1 += a[n/+][n/+];
cout<<ans1<<" "<<ans2<<endl;
}
return ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,086
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,561
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,410
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,183
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,820
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,903