B - Christmas Trees
https://atcoder.jp/contests/abc334/tasks/abc334_b
思路
对于起始种树点A 在 [L, R]区间的位置情况,三种
A < L
A> R
A>=L, A<=R
Code
https://atcoder.jp/contests/abc334/submissions/48822474
LL a, m, l, r; int main() { cin >> a >> m >> l >> r; if (a < l){ LL diffl = abs(l - a); LL numl = diffl / m; if (diffl % m == 0){ numl--; } // assert(1); LL diffr = abs(r - a); LL numr = diffr / m; LL total = numr - numl; cout << total << endl; return 0; } else if (a > r){ LL diffl = abs(a - l); LL numl = diffl / m; LL diffr = abs(a - r); LL numr = diffr / m; if (diffr % m == 0){ numr--; } LL total = numl - numr; cout << total << endl; return 0; } else { LL diffl = abs(a - l); LL numl = diffl / m; LL diffr = abs(r - a); LL numr = diffr / m; LL total = numr + numl + 1; cout << total << endl; return 0; } return 0; }
标签:diffr,numr,LL,Trees,abs,numl,Christmas,diffl From: https://www.cnblogs.com/lightsong/p/17936675.html