第一题有更好的思路吗? 对称数组 int main() { int m, n; string tmp; cin >> n >> m; vector<vector<int>> vec(n, vector<int>(m,0)); for (int i = 0; i < n; ++i) { cin >> tmp; for (int j = 0; j < m; ++j) { vec[i][j] = tmp[j]- '0'; } } int s = 0; for(int i = 0 ; i < n/2; ++i) { for(int j = 0 ; j < m/2; ++j) { int t = vec[i][j] + vec[n-1-i][j] + vec[i][m-1-j] + vec[n-1-i][m-1-j]; if(t == 2) s+=2; else if(t < 2) s+=t; else s+=(4-t); } } if(n%2 == 1) { for(int j = 0; j < m/2; ++j) { if(vec[n/2][j] != vec[n/2][m-1-j]) ++s; } } if(m%2 == 1) { for(int j = 0; j < n/2; ++j) { if(vec[j][m/2] != vec[n-1-j][m/2]) ++s; } } cout <<s <<endl; return 0; }
点赞 评论
牛客网
牛客企业服务