QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#243434#6621. Luggage LockHe2717970784Compile Error//C++171.8kb2023-11-08 11:18:432023-11-08 11:18:45

Judging History

你现在查看的是最新测评结果

  • [2023-11-08 11:18:45]
  • 评测
  • [2023-11-08 11:18:43]
  • 提交

answer

#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<map>
using namespace std;
const int INF = 1e8;

int sign(int x) {
	if (x > 0) {
		return 1;
	}
	if (x < 0) {
		return -1;
	}
	return 0;
}

bool judge(int x, int y) {
	x = sign(x), y = sign(y);
	if (x * y < 0) {
		return 0;
	}
	return 1;
}

int solve() {
	string a, b;
	cin >> a >> b;
	vector<int>v(4, 0);
	for (int i = 0; i < 4; i++) {
		v[i] = b[i] - a[i];
	}
	queue<vector<int>>q;
	vector<vector<int>>Vector;
	map<vector<int>, int>vis;
	vis[v] = 1;
	q.push(v);
	Vector.push_back(v);
	int idx = 0;
	while (!q.empty()) {
		vector<int>pre = q.front();
		q.pop();
		for (int i = 0; i < 4; i++) {
			vector<int>now = pre;
			now[i] = (now[i] + 10) % 10;
			if (!vis[now]) {
				vis[now] = 1;
				q.push(now);
				Vector.push_back(now);
			}
			now[i] -= 10;
			if (!vis[now]) {
				vis[now] = 1;
				q.push(now);
				Vector.push_back(now);
			}
		}
	}
	int ans = INF;
	for (int i = 0; i < (int)Vector.size(); i++) {
		int res = 0;
		while (true) {
			int val = INT_MAX;
			int j = 0;
			while (j < 4 && (!Vector[i][j])) {
				j++;
			}
			for (; j < 4; j++) {
				if ((val == INT_MAX || val == 0) || (sign(Vector[i][j]) == sign(val) && abs(Vector[i][j]) < abs(val))) {
					val = Vector[i][j];
				}
				else if (sign(Vector[i][j]) != sign(val)) {
					break;
				}
			}
			if ((val == INT_MAX) || (val == 0)) {
				break;
			}
			res += abs(val);
			for (int k = 0; k < j; k++) {
				if (Vector[i][k] == 0) {
					continue;
				}
				Vector[i][k] -= val;
			}
		}
		ans = min(ans, res);
	}
	return ans;
}

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int t = 0;
	cin >> t;
	while (t--) {
		int ans = solve();
		cout << ans << endl;
	}
	return 0;
}

Details

answer.code: In function ‘int solve()’:
answer.code:64:35: error: ‘INT_MAX’ was not declared in this scope
   64 |                         int val = INT_MAX;
      |                                   ^~~~~~~
answer.code:6:1: note: ‘INT_MAX’ is defined in header ‘<climits>’; did you forget to ‘#include <climits>’?
    5 | #include<map>
  +++ |+#include <climits>
    6 | using namespace std;