90分求助
查看原帖
90分求助
790188
bsdsdb楼主2023/3/8 22:00
#include <iostream>
#include <cmath>
#include <queue>
using namespace std;

int m, n, k, a[25][25];
struct Monkey {
	int x = 0, y, p = 0, t = 0;
} m1;
struct Point {
	int x, y;
	bool operator <(const Point xx) const {
		return a[x][y] < a[xx.x][xx.y];
	}
} p1;
priority_queue <Point, vector <Point>, less <Point> > b;

int main() {
	freopen("1.in", "r", stdin);
	freopen("1.out", "w", stdout);
	scanf("%d%d%d", &m, &n, &k);
	for (int i = 1; i <= m; i++) {
		p1.x = i;
		for (int j = 1; j <= n; j++) {
			p1.y = j;
			scanf("%d", &a[i][j]);
			b.push(p1);
		}
	}
	while (m1.t < k) {
		if (m1.x == 0) {
			if (m1.t + b.top().x * 2 + 1 <= k) {
				m1.t += b.top().x + 1;
			} else {
				break;
			}
		} else {
			if (m1.t + abs(m1.x - b.top().x) + abs(m1.y - b.top().y) + 1 + b.top().x <= k) {
				m1.t += abs(m1.x - b.top().x) + abs(m1.y - b.top().y) + 1;
			} else {
				break;
			}
		}
		m1.y = b.top().y;
		m1.x = b.top().x;
		m1.p += a[m1.x][m1.y];
		b.pop();
	}
	printf("%d", m1.p);
	return 0;
}
2023/3/8 22:00
加载中...