360第一题:
#include<iostream> #include<algorithm> #include<vector> #include<string> #include<queue> #include<stack> using namespace std; int main() { int n, m,a1; cin >> n >> m; int max=0; vector<vector<int>>a(n); for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) { cin >> a1; a[i].push_back(a1); max += a1 * 6; } int max_1=a[0][0]; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) { if (a[i][j]>max_1) max_1 = a[i][j]; } for (int z = 0; z < max_1; z++) { for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) { if (a[i][j] >= 1 && i < n - 1 && j < m - 1) { if (a[i][j] > 1) max -= 2; if (a[i][j + 1] >= 1) max -= 2; if (a[i + 1][j] >= 1) max -= 2; a[i][j] -= 1; } else if (a[i][j] >= 1 && i == n - 1 && j < m - 1) { if (a[i][j] > 1) max -= 2; if (a[i][j + 1] >= 1) max -= 2; a[i][j] -= 1; } else if (a[i][j] >= 1 && i < n - 1 && j == m - 1) { if (a[i][j] > 1) max -= 2; if (a[i + 1][j] >= 1) max -= 2; a[i][j] -= 1; } else if (a[i][j] >= 1 && i== n - 1 && j == m - 1) { if (a[i][j] > 1) max -= 2; a[i][j] -= 1; } } } cout << max; return 0; }
考试时忽略了一个细节,只过了18,下来改了改,测试了几个数据都过了,不知道还有没有错误