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 ...
随机推荐
- 在Windows下github展示代码
最近大爱Web编程,于是寻找各种代码中,然后就发现了GitHub这个网站,如果你知道Google Code,那么你就知道这个GitHub是做什么的了.不过GitHub主要是用作基于Git的分布式版本管 ...
- HDU 3916 Sequence Decomposition 【贪心】
这道题目的题意就是使用题目中所给的Gate 函数,模拟出输入的结果 当然我们分析的时候可以倒着来,就是拿输入去减 每次Gate 函数都会有一个有效范围 这道题目求的就是,找出一种模拟方法,使得最小的有 ...
- DFS 练习 (这篇真的是随笔)
目的: 输入: 3 输出: 1 2 3 1 3 2 2 1 3 2 3 1 3 1 2 3 2 1 代码如下: #include<stdio.h> ],b[],n; void dfs(in ...
- MessageBox不能前置显示的问题
在MFC的开发中,经常会遇到一些莫名奇妙的问题,可能是经验不足的原因吧. 进入正题....在手头的项目中,用MFC做的界面应用.在某一天突然发现程序界面不能进行响应,经过反复的调试后发现:Messag ...
- shiro权限框架
权限的组成部分:用户 资源 角色 权限 数据库关系表设计是根据自己项目需求设计的 account表role表(id,rolename)account_role(id,aid,rid)permissio ...
- Android编程心得-设计一个可重用的自定义Dialog
我们在实际开发过程中,会遇到一个问题,我们的Dialog如果使用一般的方法进行设置调用出来,会有很多的重复代码,如何将Dialog按照自己的思路设计呢,并让其可重用呢,下面我来介绍一下 ...
- lua序列化table表到文件中
先上代码 function luautil.serialize(t, sort_parent, sort_child) local mark={} local assign={} local func ...
- JSU省赛队员选拔赛个人赛1(Coin Change、Fibbonacci Number、Max Num、单词数、无限的路、叠筐)
JSU省赛队员选拔赛个人赛1 一.题目概述: A.Coin Change(暴力求解.动态规划) B.Fibbonacci Number(递推求解) C.Max Num(排序.比较) D.单词数 ...
- MSSQL奇技淫巧
MSSQL:获得库每个表的记录数和容量 sp_msforeachtable是MS未公开的存储过程: exec sp_msforeachtable @command1="print '?'&q ...
- ELK 之一:ElasticSearch 基础和集群搭建
一:需求及基础: 场景: 1.开发人员不能登录线上服务器查看详细日志 2.各个系统都有日志,日志数据分散难以查找 3.日志数据量大,查询速度慢,或者数据不够实时 4.一个调用会涉及到多个系统,难以在这 ...