题解:P16672 【MX-J30-T1】「FDOI-R1」擦肩而过
题目
求关于
思路
带绝对值的一元一次方程最多两个解,求
-
x-ac-bc=t -
x-ac-bc=-t
两个解是否符合要求
注意,当
(不要问我为什么知道)
代码
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
namespace zyll {
ll x, a ,b ,t;
int main() {
ll T;
cin >> T;
while (T--) {
cin >> x >> a >> b >> t;
ll ans = 0;
if (t == 0 && x % (a + b) == 0) ans++;
else {
if (x - t >= 0 && (x - t) % (a + b) == 0) ans++;
if (x + t >= 0 && (x + t) % (a + b) == 0) ans++;
}
cout << ans << "\n";
}
return 0;
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
return zyll::main();
}