Beautiful Matrix Codeforces Solution
Question
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; }
Pingback: 282A.Bit++ Codeforces Solution in C - Free Code Center
Pingback: Petya And Strings Codeforces Solution 2024 » Free Code Center