hdu4708
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
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
#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的更多相关文章
- hdu4708 Rotation Lock Puzzle
Rotation Lock Puzzle Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
随机推荐
- java String 怎么看里面有几个指定字符
我现在有一个String 字符串,我想看一下这个字符串里有几个指定的字符,比如指定字符是div求解 public class Main { public static void main(String ...
- mul16
设计思想:乘法运算本身就可以看做是一个移位相加的过程 1 1 0 1 0 = 26* 1 0 1 1 1 = 23 ...
- MVC-02 路由
ASP.NET Routing是个模式匹配系统 •应用程序使用路由表注册一种或多种模式,告诉路由系统如何处理这些与模式匹配的请求. •路由引擎在运行时接收到请求以后,它就会根据事先注册的U ...
- Windows的公共控件窗口类列表
The following window class names are provided by the common control library: ANIMATE_CLASS Creates a ...
- Spring Boot 探索系列 - 自动化配置篇
26. Logging Prev Part IV. Spring Boot features Next 26. Logging Spring Boot uses Commons Logging f ...
- 基于visual Studio2013解决算法导论之028散列表开放寻址
题目 散列表 解决代码及点评 #include <iostream> #include <time.h> using namespace std; template & ...
- 位操作 写读同步(无线) (语音1760 1700) ( 无线24l01)
************************************************************************** * 函数原型: unsigned char ISD ...
- glog另启动线程写文本日志
glog本身是很高效的,google的大牛肯定知道大规模的写日志用glog的话肯定会影响业务线程的处理,带负荷的磁盘IO谁都桑不起.比方levelDB就是默认异步写,更不用说google的三驾马车都是 ...
- Mac中使用svn进行项目管理
Mac中使用svn进行项目管理,借鉴了http://blog.csdn.net/q199109106q/article/details/8655204 下面方案多人亲測可用 转载请注明出处:http: ...
- shell中判断用法
测试结构: 测试命令可用于测试表达式条件的真假,true,则返回0,false,则返回非0:这一点c/c++有区别: 格式: test expression #expression是一个 ...