我是靠谱客的博主 拼搏小白菜,这篇文章主要介绍CodeForces 263 A.Beautiful Matrix(水~),现在分享给大家,希望可以做个参考。

Description

给出一个 55 的矩阵,只有1个1,其他全是0,每次操作可以交换任意两行两列,问至少要几次操作可以使得1位于矩阵的中心位置

Input

一个 55 的矩阵,只有1个1,其他全是0

Output

输出使得1位于矩阵的中心位置的最少操作数

Sample 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

Sample Output

3

Solution

水题, ans=abs(i3)+abs(j3),(i,j) 为1的位置

Code

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include<cstdio> #include<iostream> #include<cstring> #include<algorithm> #include<cmath> #include<vector> #include<queue> #include<map> #include<set> #include<ctime> using namespace std; typedef long long ll; typedef pair<int,int>P; const int INF=0x3f3f3f3f,maxn=100001; int main() { int ans,a; for(int i=1;i<=5;i++) for(int j=1;j<=5;j++) { scanf("%d",&a); if(a==1)ans=abs(i-3)+abs(j-3); } printf("%dn",ans); return 0; }

最后

以上就是拼搏小白菜最近收集整理的关于CodeForces 263 A.Beautiful Matrix(水~)的全部内容,更多相关CodeForces内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(60)

评论列表共有 0 条评论

立即
投稿
返回
顶部