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 00 0 0 0 10 0 0 0 00 0 0 0 00 0 0 0 0

Output

3

Input

0 0 0 0 00 0 0 0 00 1 0 0 00 0 0 0 00 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

A - Beautiful Matrix相关推荐

  1. [CF/AT]各大网站网赛 体验部部长第一季度工作报告

    文章目录 CodeForces #712 (Div. 1)--1503 A. Balance the Bits B. 3-Coloring C. Travelling Salesman Problem ...

  2. Codeforces上通过数超过5W人的题

    Codeforces上通过数超过5W人的题 共32题:1000分4题,800分28题. 编号 题号 题名 分数 通过数 1 4A Watermelon 800 x193501 2 71A Way To ...

  3. 【Codeforces】【161Div2】

    [题目来源]http://www.codeforces.com/contest/263 [A. Beautiful Matrix] [解析]模拟即可.按照题目的意思,找到1所在的位置(x, y),然后 ...

  4. HDU Redraw Beautiful Drawings 推断最大流是否唯一解

    点击打开链接 Redraw Beautiful Drawings Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 ...

  5. 2019ICPC南京网络赛A题 The beautiful values of the palace(三维偏序)

    2019ICPC南京网络赛A题 The beautiful values of the palace https://nanti.jisuanke.com/t/41298 Here is a squa ...

  6. 给matrix重新列名_如何认真升级Mac终端(甚至给它一个Matrix主题)

    给matrix重新列名 by Marcus Gardiner 通过马库斯·加德纳(Marcus Gardiner) 如何认真升级Mac终端(甚至给它一个Matrix主题) (How to seriou ...

  7. hihocoder 1580 Matrix(北京icpc2017网络赛)

    #1580 : Matrix 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 Once upon a time, there was a little dog YK. On ...

  8. 2017 ACM-ICPC北京网络赛: C. Matrix(DP)

    #1580 : Matrix 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 Once upon a time, there was a little dog YK. On ...

  9. Programmer Competency Matrix

    [原文:http://www.indiangeek.net/wp-content/uploads/Programmer%20competency%20matrix.htm] [译文:http://st ...

最新文章

  1. 在监视器(Monitor)内部,是如何做线程同步的?程序应该做哪种级别的同步?
  2. linux视频教程之进程管理
  3. 【Android应用开发】 Universal Image Loader ( 使用简介 | 示例代码解析 )
  4. Module 'matplotlib' has no 'contourf' member 使用Python导入matplotlib模块报错
  5. 【struts2】struts2工作流程
  6. Java常见的系统路径与获取方法
  7. html5 td中的5它空隙--待解决
  8. 辨异 —— 行星 vs 恒星
  9. 【前端统计图】echarts实现单条折线图
  10. uiwebview 修改html,修改UIWebView加载的html文本属性
  11. php 返回的缓存数据,基于PHP输出缓存(output_buffering)的深入理解
  12. iQOO Neo6入网:骁龙8旗舰平台+80W快充
  13. python元类是什么_谈谈Python中元类Metaclass(一):什么是元类
  14. 美国数学家维纳智力早熟,11岁就上了大学,他曾在1935-1936年 应邀参加中国清华大学讲学,一次他参加某个重要会议,年轻的脸孔 引人注意,于是有人询问他的年龄,他回答说“我年龄的立方是个4位数
  15. 非受检异常_Java异常(Exception)类型及处理
  16. 大气压力换算公式_压强单位bar,psi,pa,mpa,kg换算公式
  17. Floyd's Tortoise and Hare循环检测算法
  18. 计算机图形学---简单光照明模型知识汇总
  19. DataX二次开发——(6)kafkareader、kafkawriter的开发
  20. 快应用的用法和常见问题解答(上)

热门文章

  1. Linux 命令之 find -- 查找文件和目录/搜索文件和目录
  2. JSP文件中Java代码的几种形式(JSP脚本)
  3. 设置图像的title_【HTML】2 图像标签和属性
  4. python单用户登录_Django实现单用户登录的方法示例
  5. php文件上传漏洞waf,文件上传绕过WAF
  6. 晨风机器人怎么买奴隶_潮牌复刻和正品该怎么抉择???带你了解了解
  7. python从列表随机取出多个数据_【python】从数组随机取数据
  8. ajax实现表单验证 html,Ajax+ajax做的表单验证
  9. java集合的添加方法_深入理解java集合框架之---------Arraylist集合 -----添加方法
  10. 如何将四元数方向转化为旋转举证_是否有将四元数旋转转换为欧拉角旋转的算法?...