Beautiful Matrix Codeforces Solution

Beautiful Matrix Codeforces Solution

Question

Beautiful Matrix Codeforces Solution

Problem Specification


The goal of Codeforces Problem 263A is to determine the fewest moves required to convert a given 5×5 matrix into a “beautiful” matrix. A “beautiful” matrix is one in which the number 1 is in the center and the remaining elements are placed in a 3×3 grid around the center.

Understanding the Issue || Beautiful Matrix Codeforces Solution

Let’s start with a thorough understanding of the problem needs before diving into the solution. We are given a 5×5 matrix and must determine the smallest number of moves required to place the number 1 in the middle of the matrix. A move is defined as replacing the number 1 with an adjacent (horizontal or vertical) element. The goal is to create a “beautiful” matrix by arranging the other elements in a 3×3 grid around the number 1.

Solution in C

#include<stdio.h>

int main()
{
int i,j,x=0;
for(i=1;i<=5;i++){
for(j=1;j<=5;j++){
scanf("%d",&x);
if(x==1){
printf("%d\n",abs(i-3)+abs(j-3));
}

}

}
return 0;
}

Codeforces 282A. bit++ solution in C


2 thoughts on “Beautiful Matrix Codeforces Solution”

  1. Pingback: 282A.Bit++ Codeforces Solution in C - Free Code Center

  2. Pingback: Petya And Strings Codeforces Solution 2024 » Free Code Center

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top
NEW TOXIC ROCKET CYCLE DECK in Clash Royale 2023 Best Deck in Clash Royale Best Deck for Arena 8 in Clash Royale Best Hog deck for Pro players Best Clash Royale Deck