Beautiful Matrix

简介: Beautiful Matrix

文章目录

一、Beautiful Matrix

总结


一、Beautiful Matrix

本题链接:Beautiful Matrix


题目:


A. Beautiful Matrix

time limit per test2 seconds

memory limit per test256 megabytes

inputstandard input

outputstandard output

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:


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

Swap two neighboring matrix columns, that is, columns with indexes j and j + 1 for 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


本博客给出本题截图:

image.png

题意:给一个初始的图,每次只能交换相邻的行和列,要求最少通过几次能把数字1交换到图的中央,其实就是去求一下1到图中点的曼哈顿距离。

AC代码

#include <iostream>
#include <algorithm>
using namespace std;
const int N = 10;
int a[N][N];
int x, y;
int main()
{
  for (int i = 0; i < 5; i ++ )
    for (int j = 0; j < 5; j ++ )
    {
      cin >> a[i][j];
      if (a[i][j]) 
      {
        x = i;
        y = j;
      }
    }
  cout << abs(x - 2) + abs(y - 2) << endl;
  return 0;
}

总结

zeroes 零

index 索引

matrix 模板

row 行

column 列

apply 申请

transformation 变换

integer 整数

水题,不解释


目录
相关文章
【推荐】排序模型的评价指标nDCG
nDCG(Normalized Discounted Cumulative Gain)归一化折损累计增益是一种用于评估排序模型性能的指标,它考虑了两个方面:排序的正确性和相关性的程度。
5423 0
|
开发框架 安全 .NET
常见ASPX木马报错原因及解决方案
常见ASPX木马报错原因及解决方案
1436 0
|
Kubernetes Ubuntu 安全
Linux|科普扫盲帖|配置网络软件源---阿里云镜像仓库服务使用(centos,Ubuntu)
Linux|科普扫盲帖|配置网络软件源---阿里云镜像仓库服务使用(centos,Ubuntu)
4920 0
|
人工智能 语音技术 流计算
一图掌握通义千问:模型生态与应用场景全览
通义千问(Qwen)系列提供全栈开源AI能力,涵盖语言、视觉、语音等多模态应用。旗舰模型Qwen3-Max性能领先,支持92种语言翻译与高精度语音识别,具备强大代码生成与图像处理能力,助力开发者与企业高效构建智能应用。
1618 2
一图掌握通义千问:模型生态与应用场景全览
|
人工智能 弹性计算 自然语言处理
史上首次!万卡AI集群支撑双11,通义千问大规模落地
2025年双11,阿里云提供超千万核ECS算力及万卡灵骏智算集群,支撑淘宝推荐等核心业务性能提升超30%。通义千问大模型大规模落地,Qwen-MT单日调用超14亿次,助力商品出海、客服与经营分析,全面赋能双11智能化升级。
1650 0
史上首次!万卡AI集群支撑双11,通义千问大规模落地
|
存储 缓存 测试技术
阿里云服务器经济型e实例怎么样?性能、价格与适用场景全解析
阿里云服务器经济型e实例2核2G3M带宽40G ESSD Entry云盘价格只要99元1年,而且续费不涨价。经济型e实例是阿里云面向个人开发者、学生以及小微企业推出的一款入门级云服务器。这款实例以其高性价比和灵活的配置,迅速赢得了市场的青睐。那么,阿里云服务器经济型e实例到底怎么样?是否值得购买呢?本文将为您解析经济型e实例的性能、价格与适用场景,以供参考。
|
Python
【Python】已解决:ValueError: Worksheet named ‘Sheet’ not found
【Python】已解决:ValueError: Worksheet named ‘Sheet’ not found
1951 0
|
数据库连接 程序员 C#
C#(WPF)连接SQLite数据库,利用ViewModel显示数据
对于入门c#(WPF)的初级程序猿
2008 0
C#(WPF)连接SQLite数据库,利用ViewModel显示数据
|
运维 程序员 项目管理
一份【软件工程】的学习指南已到达,请注意查收!!
该文章提供了一份软件工程的学习指南,包括学习软件工程的重要性、基本内容概览以及建议的学习方法和路径。
一份【软件工程】的学习指南已到达,请注意查收!!
|
自然语言处理 前端开发 JavaScript
V8引擎的运行原理
【9月更文挑战第1天】V8引擎的运行原理
741 0