D - AtCoder Wallpaper(abc)

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

代码:

cpp 复制代码
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);
}
相关推荐
码爸4 分钟前
线性回归算法
算法·机器学习·线性回归
Coder-magician31 分钟前
《代码随想录》刷题打卡day51:图论-part09(dijistra堆优化,Bellman_ford算法)
算法·图论
Nil20840 分钟前
leetcode 763划分字母区间
算法·leetcode·职场和发展
不会就选b1 小时前
算法日常・每日刷题--<动态规划>20
算法·leetcode·动态规划
青少儿编程课堂2 小时前
迪杰斯特拉(Dijkstra)算法:单源最短路与赛场路线规划
c++·python·算法·bfs·信息学竞赛
不会就选b2 小时前
算法日常・每日刷题--<动态规划>19
算法·leetcode·职场和发展
没有钱的钱仔3 小时前
协方差矩阵含义
算法·机器学习·矩阵
垆边人似月.3 小时前
华为机试题 :和为 K 的子数组个数
算法·leetcode·华为
三*一4 小时前
优化修整算法
前端·javascript·算法