自学内容网 自学内容网

D - AtCoder Wallpaper(abc)

思路:f(c, d) + f(a, b) - f(a, d) - f(c, b)

代码:

int f(int x, int y){
    if(y % 2 == 0){
        y = y / 2;
        int ans = y * (x / 4) * 8;
        x %= 4;
        if(x == 1){
            ans += y * 3;
        }else if(x == 2){
            ans += y * 6;
        }else if(x == 3){
            ans += y * 7;
        }
        return ans;
    }else{
        y /= 2;
        int ans = y * (x / 4) * 8 + 2 * (x / 4) * 2;
        x %= 4;
        if(x == 1){
            ans += y * 3 + 2;
        }else if(x == 2){
            ans += y * 6 + 3;
        }else if(x == 3){
            ans += y * 7 + 3;
        }
        return ans;
    }
}


void solve(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if(a < 0){
        int cnt = (-a + 3) / 4;
        a += cnt * 4;
        c += cnt * 4; 
    }
    if(b < 0){
        int cnt = (-b + 3) / 4;
        b += cnt * 4;
        d += cnt * 4;
    }
    cout << f(c, d) + f(a, b) - f(a, d) - f(c, b);
}


原文地址:https://blog.csdn.net/weixin_73550568/article/details/139123804

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!