HDU 4708 Rotation Lock Puzzle (简单题)
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
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).
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
按照题目意思去旋转。
求最大值
/* *******************************************
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 ;
}
HDU 4708 Rotation Lock Puzzle (简单题)的更多相关文章
- HDU 4708:Rotation Lock Puzzle
Rotation Lock Puzzle Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- HDU 4708 Rotation Lock Puzzle(模拟)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4708 题目大意:给定一个方形矩阵,边长为3-10的奇数.每一圈的数字可以沿着顺时针方向和逆时针方向旋转 ...
- hdu 4708 Rotation Lock Puzzle 2013年ICPC热身赛A题 旋转矩阵
题意:给出一个n*n的矩阵,旋转每一圈数字,求出对角线可能的最大值,以及转到最大时的最小距离. 只要分析每一层就可以了,本来想用地址传递二维数组,发现行不通,改了一下就行了. 这里有个坑,比如: 1 ...
- 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/O ...
- hdu4708 Rotation Lock Puzzle
Rotation Lock Puzzle Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- HDUOJ---(4708)Rotation Lock Puzzle
Rotation Lock Puzzle Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- HDU 2802 F(N)(简单题,找循环解)
题目链接 F(N) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...
- Rotation Lock Puzzle
Problem Description Alice was felling into a cave. She found a strange door with a number square mat ...
- HDOJ(HDU) 2123 An easy problem(简单题...)
Problem Description In this problem you need to make a multiply table of N * N ,just like the sample ...
随机推荐
- P2184 【贪婪大陆】
看到全是线段树或者树状数组写法,就来提供一发全网唯一cdq分治三维偏序解法吧 容易发现,这个题的查询就是对于每个区间l,r,查询有多少个修改区间li,ri与l,r有交集 转化为数学语言,就是查询满足l ...
- 编程六月定律 | 外刊IT评论网
编程六月定律 上周,我被迫对一个很老的项目做一些修改.麻烦是,当开始着手时,我真的记不清这个项目究竟有多老了. 这实际上是我使用Codeigniter实现的第一个MVC项目.打开项目文件后,很多东西都 ...
- 20165203《Java程序设计》第三周学习总结
教材学习内容总结 1.类: (1)类的声明:class+类名 (2)类体:成员变量的声明+方法(局部变量+语句) 注意: 方法体内声明的局部变量只在方法内有效和书写位置有关. 局部变量和成员变量同名: ...
- Python 让两个print()函数的输出打印在一行内
1.两个连续的print()函数为什么在输出时内容会分行显示? 解:print()中有两个默认参数 sep 和 end,其中sep是代替分隔符,end是代替末尾的换行符,默认使用‘,’代替空格,且默认 ...
- css实现360导航首页超链接变色
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- Android 中.aar文件生成方法与用法
https://i.cnblogs.com/EditPosts.aspx?opt=1 无论是用Eclipse还是用Android Studio做android开发,都会接触到jar包,全称应该是:Ja ...
- HBase(三)HBase架构与工作原理
一.系统架构 注意:应该是每一个 RegionServer 就只有一个 HLog,而不是一个 Region 有一个 HLog. 从HBase的架构图上可以看出,HBase中的组件包括Client.Zo ...
- USACO 5.5 Picture
PictureIOI 1998 A number, N (1 <= N < 5000), of rectangular posters, photographs and other pic ...
- win7下docker环境搭建nginx+php-fpm+easyswoole+lavarel+mysql开发环境
win7环境基础在上一篇win7下docker环境搭建nginx+php-fpm+easyswoole开发环境中已经详细叙述搭建完成 本篇文章将叙述如何在上述基础上搭建laravel开发环境,这个其实 ...
- thinkphp中导入和使用阿里云OSSsdk
照做绝对行,在ThinkPHP中,第三方库都放在ThinkPHP/Library/Vendor/路径下. 1.下载OSS PHP SDK:https://help.aliyun.com/documen ...