Karl_Wan @ 2024-11-04 14:34:14
RT
by c22j33c43 @ 2024-11-04 14:42:09
我靠,0提交,161解决!
这题你让它关于中心对称不就行了,能不翻就不翻
by c22j33c43 @ 2024-11-04 15:15:20
看一下这个可不可以
#include<bits/stdc++.h>
using namespace std;
int a[1001][1001],n,m,p,ans;
int main(){
//freopen("2.in","r",stdin);
cin>>n;
m=n/2;
if(n%2!=0) p=1;
for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) cin>>a[i][j];
for(int i=1;i<=m;i++){
for(int j=1;j<=m;j++){
if(a[i][j]==a[n-i+1][j]&&a[i][n-j+1]==a[n-i+1][n-j+1]&&a[i][j]==a[n-i+1][n-j+1]) continue;
else{
int shu=a[i][j]+a[n-i+1][j]+a[i][n-j+1]+a[n-i+1][n-j+1];
if(shu>2) ans+=(4-shu);
else if(shu==2) ans+=2;
else if(shu<2) ans+=shu;
}
}
}
if(p==1){
int m1=m+1;
for(int i=1;i<=m;i++){
if(a[m1][m1-i]==a[m1][m1+i]&&a[m1+i][m1]==a[m1-i][m1]&&a[m1][m1-i]==a[m1-i][m1]){
continue;
}
else{
int shu=a[m1][m1-i]+a[m1][m1+i]+a[m1+i][m1]+a[m1-i][m1];
if(shu>2) ans+=(4-shu);
else if(shu==2) ans+=2;
else if(shu<2) ans+=shu;
}
}
}
cout<<ans;
return 0;
}
by c22j33c43 @ 2024-11-04 15:24:52
好像有点抽象,加点注释吧。
#include<bits/stdc++.h>
using namespace std;
int a[1001][1001],n,m,p,ans;
int main(){
//freopen("2.in","r",stdin);
cin>>n;
m=n/2;
if(n%2!=0) p=1; //判断n为奇或偶
for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) cin>>a[i][j];
for(int i=1;i<=m;i++){
for(int j=1;j<=m;j++){
if(a[i][j]==a[n-i+1][j]&&a[i][n-j+1]==a[n-i+1][n-j+1]&&a[i][j]==a[n-i+1][n-j+1]) continue;//关于中心对称的四个数是否相同,是就调过
else{
int shu=a[i][j]+a[n-i+1][j]+a[i][n-j+1]+a[n-i+1][n-j+1];//例子:三个1加一个0,shu=3,只翻一次,0翻成1,ans+=1;
if(shu>2) ans+=(4-shu);
else if(shu==2) ans+=2;
else if(shu<2) ans+=shu;//算最小翻的次数
}
}
}
if(p==1){
int m1=m+1;
for(int i=1;i<=m;i++){
if(a[m1][m1-i]==a[m1][m1+i]&&a[m1+i][m1]==a[m1-i][m1]&&a[m1][m1-i]==a[m1-i][m1]){
continue;
}
else{
int shu=a[m1][m1-i]+a[m1][m1+i]+a[m1+i][m1]+a[m1-i][m1];
if(shu>2) ans+=(4-shu);
else if(shu==2) ans+=2;
else if(shu<2) ans+=shu;
}
}
}//同理,算中间的"十"字架(怕出错就单独拿了出来 )
cout<<ans;
return 0;
}