poj3484 Showstopper 二分

时间:2022-09-11 07:05:13

  题目地址

  二分用的很是巧妙!关键是抽象出问题本质。

 #include <cstdio>
#include <string>
#include <cstring>
const int maxn = ;
#define ull unsigned long long
ull X[maxn], Y[maxn], Z[maxn], C[maxn];
ull N;
ull judge(const ull &mid) {
ull sum = ;
for (int i = ; i < N; i++) {
if (mid >= Y[i]) {
sum += C[i];
} else if (mid >= X[i]) {
sum += ((mid-X[i])/Z[i]+);
}
}
return sum;
}
char buf[];
bool input() {
int f = ;
N = ;
while ((f = ((gets(buf) != NULL))) && strlen(buf) > ) {
sscanf(buf, "%llu %llu %llu", &X[N], &Y[N], &Z[N]);
N++;
}
return f || N;
}
int main(void) {
for (;input();) {
if (!N) {
continue;
}
ull last = ;
for (int i = ; i < N; i++) {
C[i] = (Y[i] - X[i])/Z[i] + ;
last ^= C[i];
}
if (!(last & )) {
printf("no corruption\n");
} else {
ull l = , u = 0xffffffff;
for (;(u-l)>;) {
ull mid = (u+l) >> ;
if (judge(mid)&) {
u = mid;
} else {
l = mid +;
}
}
printf("%llu %llu\n", l, judge(l)-judge(l-));
}
}
return ;
}