A - Beautiful Matrix

Problem description

You've got a 5 × 5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix:

  1. Swap two neighboring matrix rows, that is, rows with indexes i and i + 1 for some integer i (1 ≤ i < 5).
  2. Swap two neighboring matrix columns, that is, columns with indexes j and j + 1for some integer j (1 ≤ j < 5).

You think that a matrix looks beautiful, if the single number one of the matrix is located in its middle (in the cell that is on the intersection of the third row and the third column). Count the minimum number of moves needed to make the matrix beautiful.

Input

The input consists of five lines, each line contains five integers: the j-th integer in the i-th line of the input represents the element of the matrix that is located on the intersection of the i-th row and the j-th column. It is guaranteed that the matrix consists of 24 zeroes and a single number one.

Output

Print a single integer — the minimum number of moves needed to make the matrix beautiful.

Examples

Input

0 0 0 0 0
0 0 0 0 1
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0

Output

3

Input

0 0 0 0 0
0 0 0 0 0
0 1 0 0 0
0 0 0 0 0
0 0 0 0 0

Output

1
解题思路:题目的意思就是有一个5*5的矩阵,其中只有一个元素值为1,其余元素的值全部为0,从元素1这个位置移到中心点(2,2)(下标从0~4)的过程中,每次只能向上、下、左、右(其中一个方向)移动一步,求最小的移动步数。简单模拟一下过程即可推出:设1元素的坐标为(row,col),则移动的最小步数为abs(row-2)+abs(col-2),简单AC。
AC代码:
 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 int main(){
 4     int row,col,x;
 5     for(int i=0;i<5;++i){
 6         for(int j=0;j<5;++j){
 7             cin>>x;
 8             if(x){row=i;col=j;}
 9         }
10     }
11     cout<<abs(row-2)+abs(col-2)<<endl;
12     return 0;
13 }
 

转载于:https://www.cnblogs.com/acgoto/p/9122996.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/353570.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

MATLAB中用FDATool设计滤波器及使用

from: http://blog.sina.com.cn/s/blog_3e4367660100nyz1.html 1. 在Matlab中键入fdatool运行Filter Design and Analysis Tool。具体使用请参见Matlab Help中的Signal Processing Toolbox->FDATool。 2. 在fdatool工具中应该注意的几个问题&#xff1a;(a)Fstop&#xf…

电商等大型网站高可用,高负载架构借鉴方案(转载)

任何一个大型网站都是经历用户积累然后成长&#xff0c;从一台服务器到多台服务器才能构架支撑网站现有数据、用户、页面请求等。大型网站(如淘宝、京东等)的系统架构并不是开始设计就具备完整的高性能、高可用、安全等特性&#xff0c;它总是随着用户量的增加&#xff0c;业务…

《Hadoop实战》的笔记-2、Hadoop输入与输出

from: http://book.douban.com/annotation/17068812/ 这一问题本书只在第三章简单说了一下读写HDFS&#xff0c;虽然能说明问题&#xff0c;但是本着第一遍读书应该把书读厚的原则&#xff0c;我觉得很有必要自行展开一番。再说凡是万变不离其宗嘛&#xff0c;任何程序都是从“…

复制模式和扩展模式_扩展剂:模式还是反模式?

复制模式和扩展模式扩展器模式在最近几年变得很流行&#xff0c;甚至已经在OSGi标准&#xff08;例如&#xff0c;蓝图服务和Web应用程序规范&#xff09;中使用。 在处女座&#xff0c;我们从一开始就与扩展程序一起工作&#xff0c;但是尽管它们具有优势&#xff0c;但它们仍…

Ubuntu 18.04 下安装pip3及pygame模块

1.Ubuntu下pip3的安装、升级、卸载 安装pip3 sudo apt-get install python3-pip 升级pip3 sudo pip3 install --upgrade pip 卸载pip3 sudo apt-get remove python3-pip 2.安装pygame sudo pip3 install pygame 3.验证pygame是否安装成功&#xff0c;如果安装成功则会出现如下图…

linux 禁止账户远程登录

为了安全或其他原因&#xff0c;经常需要禁止某些用户远程登录&#xff0c;方法整理如下&#xff1a; 1. 禁止root账户远程登录 root账户下修改 /etc/ssh/sshd_config # vi /etc/ssh/sshd_config 找到 PermitRootLogin yes 这一句&#xff0c;将yes改成no&#xff0c;退出保存…

ANTLR和网络:一个简单的例子

网络上的ANTLR&#xff1a;为什么&#xff1f; 我开始在MS-DOS上编写我的第一个程序。 因此&#xff0c;我非常习惯在计算机上安装工具。 但是在2016年&#xff0c;网络无处不在&#xff0c;因此那里也可能需要我们的语言。 可能的情况&#xff1a; ANTLR 也在网络上&#xf…

下一秒

好想能看到 你嘴角微笑 最好在下一秒 好想能听到 你轻声歌唱 最好在下一秒 纯白棒球帽 墨绿色衣角 时间静止的美好 默契发生在每个下一秒 爱上同一种口味的蛋糕 不约而同哼唱一段曲调 喜欢这样看你傻傻的笑 好想能这样 就白头到老 最好从下一秒 转载于:https://www.cnblogs.com…

类加载器 jboss_JBoss AS 7类加载说明

类加载器 jboss这是示例章节&#xff0c;摘自Francesco Marchioni编辑的JBoss AS 7 Configuration Deployment and Administration一书&#xff0c;该书正在运行一个名为mastertheboss.com的JBoss门户。 根据Java EE规范的要求&#xff0c;理想情况下&#xff0c;应用程序服务器…

【转】Docker 容器化核心概念

DockerVM vs DockerDocker 是一个开源的应用容器引擎&#xff0c;让开发者可以打包他们的应用以及依赖包到一个可移植的容器中&#xff0c;然后发布到任何流行的Linux机器上&#xff0c;也可以实现虚拟化。容器是完全使用沙箱机制&#xff0c;相互之间不会有任何接口。 示例一&…

弹簧活性样品

Spring-Reactive旨在为基于Spring的项目带来响应式编程支持 &#xff0c;并且有望在Spring 5的时间表中提供。 我的意图是使用此模型为REST端点行使一些非常基本的签名。 在继续之前&#xff0c;请允许我确认整个样本完全基于塞巴斯蒂安德勒兹&#xff08;SbastienDeleuze&…

团队作业_1_博客1(分工理解)

对于团队大作业分工&#xff08;服务端&#xff09;的理解&#xff1a; 这次大作业一经出炉&#xff0c;还是感觉很有意思的&#xff0c;虽然之前老师已经提及会出这么一个大作业来训练我们的能力&#xff0c;但是真的看到作业的出现&#xff0c;还是很惊喜的。 团队作业的分工…

pojo类继承pojo类_如何编写更好的POJO服务

pojo类继承pojo类在Java中&#xff0c;您可以轻松地在Plain Old Java Object&#xff08;POJO&#xff09;类中实现一些业务逻辑&#xff0c;并且可以在高级服务器或框架中轻松运行它们。 有许多服务器/框架&#xff0c;例如JBossAS&#xff0c;Spring或Camel等&#xff0c;它们…

国外机构操盘图

转载于:https://www.cnblogs.com/carl2380/p/9139020.html

代码气味–第二部分

在上一篇文章《代码气味–第一部分》中 &#xff0c;我谈到了膨胀器&#xff1a;它们是代码气味&#xff0c;可以识别为长方法&#xff0c;大型类&#xff0c;基元痴迷&#xff0c;长参数列表和数据块。 在这一篇中&#xff0c;我想深入研究面向对象的滥用者和变更阻止者 。 面…

solr 启动、停止

启动命令&#xff1a; solr start 停止命令 solr stop -all 转载于:https://www.cnblogs.com/yby120/p/9139791.html

第一篇博客测试

第一次发博客测试&#xff0c;看看都能进行什么操作。 再编辑一下&#xff0c;发表的时间就又改了&#xff1f; 没想到这个测试也有这么多人访问&#xff0c;那我把我的测试结果也贴出来供大家参考&#xff1a; 1. 无论怎么编辑&#xff0c;发表时间不会更改&#xff1b; 2. 编…

hadoop 提交程序并监控运行

程序编写及打包 使用maven导入第三方jar pom.xml <?xml version"1.0" encoding"UTF-8"?> <project xmlns"http://maven.apache.org/POM/4.0.0"xmlns:xsi"http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation&qu…

digester_Apache Digester示例–轻松配置

digester解决问题–硬编码&#xff0c;需要为您的应用程序创建自定义配置&#xff0c;例如struts配置文件&#xff0c;仅通过更改文件即可改变应用程序的行为。 Apache Digester可以轻松为您完成此任务。 使用Apache Digester相当容易将XML文档转换为相应的Java bean对象层次结…

MFC状态栏编程(显示系统时间和进度条)

显示系统时间 1、 在状态栏中设置两个新的栏位Timer和Progress。首先到ResourceView中编辑String Table&#xff0c;增加IDS_TIMER(时间),PROGRESS(进度)。然后在MainFrame中修改indicators数组&#xff0c;插入IDS_TIMER和IDS_PROGRESS。插入的位置&#xff0c;即为显示的位置…