delete pics to save space
This commit is contained in:
44
history_source/挑战程序设计竞赛/2.7.2.cpp
Normal file
44
history_source/挑战程序设计竞赛/2.7.2.cpp
Normal file
@ -0,0 +1,44 @@
|
||||
#include<cstdio>
|
||||
#include<algorithm>
|
||||
using namespace std;
|
||||
int n,M[45][45],a[45];
|
||||
void init()
|
||||
{
|
||||
scanf("%d",&n);
|
||||
int i,j;
|
||||
for(i=0;i<n;i++)
|
||||
for(j=0;j<n;j++)
|
||||
scanf("%d",&M[i][j]);
|
||||
}
|
||||
void solve()
|
||||
{
|
||||
int res=0;
|
||||
for(int i=0;i<n;i++)
|
||||
{
|
||||
a[i]=-1;
|
||||
for(int j=0;j<n;j++)
|
||||
if(M[i][j]==1) a[i]=j;
|
||||
}
|
||||
for(int i=0;i<n;i++)
|
||||
{
|
||||
int pos=-1;
|
||||
for(int j=i;j<n;j++)
|
||||
if(a[j]<=i)
|
||||
{
|
||||
pos=j;
|
||||
break;
|
||||
}
|
||||
for(int j=pos;j>i;j--)
|
||||
{
|
||||
swap(a[j],a[j-1]);
|
||||
res++;
|
||||
}
|
||||
}
|
||||
printf("%d\n",res);
|
||||
}
|
||||
int main()
|
||||
{
|
||||
init();
|
||||
solve();
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user