wa5, 90pts 求各位大佬 浅看一下我的代码qwq
查看原帖
wa5, 90pts 求各位大佬 浅看一下我的代码qwq
596291
Qust_yanzhenbin楼主2023/9/27 20:41

看了第一篇题解,感觉差不多 结果wa5了... 看不太懂别人的板子qwq

#include <bits/stdc++.h>
using namespace std;

#define int long long

const int N = 20;
const int M = 1e6;

struct Node {
	int c, p, l;
} per[N];
int n;

int ex_gcd(int a, int b, int &x, int &y) {
	if (!b) {
		x = 1, y = 0;
		return a;
	}
	int ret = ex_gcd(b, a % b, y, x);
	y -= a / b * x;
	return ret;
}

signed main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		int c, p, l;
		cin >> c >> p >> l;
		per[i] = {c, p, l};
	}
	int res = -1;

	for (int m = 1; m <= M; m++) {
		bool ok = true;
		for (int i = 1; i + 1 <= n; i++) {
			for (int j = i + 1; j <= n; j++) {
				int a = (((per[i].p - per[j].p) % m) + m) % m;
				int c = (((per[j].c - per[i].c) % m) + m) % m;

				int k1, k2;
				int d = ex_gcd(a, m, k1, k2);
				if (c % d == 0) {
					int x = c / d * k1;
					x = (x % (m / d) + (m / d)) % (m / d);
					if (x <= min(per[i].l, per[j].l)) {
						ok = false;
						break;
					}
				}
			}
			if (!ok) break;
		}
		if (ok) {
			res = m;
			break;
		}
	}

	cout << res << endl;
	return 0;
}
2023/9/27 20:41
加载中...