题解
2023-06-27 19:44:27
发布于:上海
139阅读
0回复
0点赞
#include <bits/stdc++.h>
using namespace std;
int n, a[110][110], d[8][2] = {-1, -1, 0, -1, 1, -1, -1, 0, 1, 0, -1, 1, 0, 1, 1, 1}, ans = 0;
struct data {
int x, y, w;
};
vector<data> v;
bool cmp(data x, data y) {
if (x.w != y.w)
return x.w > y.w;
else if (x.x != y.x)
return x.x < y.x;
else
return x.y < y.y;
}
int compute(int x, int y) {
int res = a[x][y];
for (int i = 0; i < 8; i++) {
int nx = x + d[i][0], ny = y + d[i][1];
if (nx >= 1 && nx <= n && ny >= 1 && ny <= n) {
res *= a[nx][ny];
}
}
return res;
}
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
cin >> a[i][j];
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
int cur = compute(i, j);
ans = max(ans, cur);
v.push_back({i, j, cur});
}
}
sort(v.begin(), v.end(), cmp);
for (auto item : v) {
if (item.w == ans)
cout << item.x << " " << item.y << endl;
else
break;
}
return 0;
}
全部评论 2
tai ku la
2023-08-13 来自 广东
1牛b
2023-07-13 来自 浙江
0
有帮助,赞一个