版本比较
题解:P14632 [2018 KAIST RUN Fall] Rising Sun
正文
增加 8 行删除 8 行
56 行未改动5758596061616263646566666768697071727374747576777879808182838484858687888989909192938 行未改动10210310410510610610710810911011111211211311411411511611756 行未改动int main(){ ios::sync_with_stdio(0); cin.tie(0), cout.tie(0);
cin >> n; for(LL i = 0; i < 2 * n; i++) cin >> a[i]; cin >> xj;
prev_sy = 0; for(LL k = 0; k < 2 * n - 1; k++) { LL L = a[k], R = a[k + 1], p = (k % 2 == 0) ? 1 : -1, q = prev_sy - p * L; segs[k] = {L, R, p, q}; prev_sy += p * (R - L); }
yj = 0.0; for(LL k = 0; k < 2 * n - 1; k++) { if(segs[k].L <= xj and xj <= segs[k].R) { yj = segs[k].p * 1.0 * xj + segs[k].q; break; } }
cnt = 0; for(LL i = 0; i < 2 * n; i++) if(a[i] < xj) x0l[cnt++] = a[i];
maxx = -INF; for(LL i = 0; i < cnt; i++) { LL x0 = x0l[i];8 行未改动 } double f = (xj * Bx0 - yj * x0) / (xj - x0); maxx = max(maxx, f); }
LL ans; if(maxx < 0) ans = 0; else ans = static_cast <LL> (ceil(maxx));
cout << ans;
return 0;}```