http://poj.org/problem?id=3484
2.Idea
Binary Search
3.Source
#define MAXN 1000006
ll x[MAXN], y[MAXN], z[MAXN];
int n;
char A[MAXN];
bool init() {
n = 0;
bool f = false;
while ((f = (gets_s(A) != NULL)) && strlen(A) > 0)
{
sscanf(A, "%lld %lld %lld", &x[n], &y[n], &z[n]);
n++;
}
return f || n;
}
ll C(ll m)
{
ll sum = 0;
for (int i = 0; i < n; i++) {
if (m < x[i]) continue;
ll t = min(m, y[i]);
sum += ((t - x[i]) / z[i] + 1);
}
return sum;
}
void solve()
{
if (n == 0) return;
ll l = 0;
ll r = 1LL << 32;
while (r - l > 1) {
ll m = (l + r) / 2;
if (C(m) & 1) {
r = m;
}
else {
l = m;
}
}
if (r == 1LL << 32) cout << "no corruption" << endl;
else cout << r << " " << C(r) - C(r - 1) << endl;
}
int main()
{
while (init()) {
solve();
}
return 0;
}
No comments:
Post a Comment