比赛 |
2025.9.13 |
评测结果 |
ATAAAAATTTTT |
题目名称 |
Transforming Pairs |
最终得分 |
50 |
用户昵称 |
ChenBp |
运行时间 |
12.042 s |
代码语言 |
C++ |
内存使用 |
3.51 MiB |
提交时间 |
2025-09-13 11:48:35 |
显示代码纯文本
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <utility>
#define ll long long
using namespace std;
// queue<pair<int, pair<ll, ll>>> q;
int main() {
freopen("Transforming.in", "r", stdin);
freopen("Transforming.out", "w", stdout);
ll t, a, b, c, d;
cin >> t;
while (t--) {
cin >> a >> b >> c >> d;
// map<pair<ll, ll>, bool> ma;
// while (!q.empty())
// q.pop();
// q.push(make_pair(0, make_pair(a, b)));
// bool ok = 0;
// while (!q.empty()) {
// int num = q.front().first, na = q.front().second.first, nb = q.front().second.second;
// q.pop();
// if (na == c && nb == d) {
// cout << num << endl;
// ok = 1;
// break;
// }
// if (na + nb <= c) {
// if (!ma.count(make_pair(na + nb, nb))) {
// ma[make_pair(na + nb, nb)] = 1;
// q.push(make_pair(num + 1, make_pair(na + nb, nb)));
// }
// }
// if (na + nb <= d) {
// if (!ma.count(make_pair(na, na + nb))) {
// ma[make_pair(na, na + nb)] = 1;
// q.push(make_pair(num + 1, make_pair(na, na + nb)));
// }
// }
// }
// if (!ok) {
// cout << "-1\n";
// }
ll ans = 0;
bool ok = true;
while (true) {
if (c < a || d < b) {
ok = false;
break;
}
if (c == a && d == b)
break;
if (c == d) {
ok = false;
break;
}
if (c > d) {
c -= d;
ans++;
} else {
d -= c;
ans++;
}
}
if (ok)
cout << ans << "\n";
else
cout << "-1\n";
}
}