Stay Hungry,Stay Foolish!

B - Christmas Trees

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;
}

 

posted @ 2023-12-30 19:07  lightsong  阅读(10)  评论(0编辑  收藏  举报
Life Is Short, We Need Ship To Travel