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);
}
相关推荐
好学且牛逼的马9 小时前
【Hot100 | 6 LeetCode 15. 三数之和】
算法
橘颂TA9 小时前
【剑斩OFFER】算法的暴力美学——二分查找
算法·leetcode·面试·职场和发展·c/c++
lkbhua莱克瓦2410 小时前
Java基础——常用算法4
java·数据结构·笔记·算法·github·排序算法·快速排序
m0_7482480210 小时前
揭开 C++ vector 底层面纱:从三指针模型到手写完整实现
开发语言·c++·算法
七夜zippoe10 小时前
Ascend C流与任务管理实战:构建高效的异步计算管道
服务器·网络·算法
Greedy Alg10 小时前
LeetCode 208. 实现 Trie (前缀树)
算法
还是码字踏实10 小时前
基础数据结构之哈希表:两数之和(LeetCode 1 简单题)
数据结构·leetcode·散列表
Kt&Rs10 小时前
11.5 LeetCode 题目汇总与解题思路
数据结构·算法·leetcode
还是码字踏实10 小时前
基础数据结构之数组的前缀和技巧:和为K的子数组(LeetCode 560 中等题)
算法·leetcode·前缀和·哈希字典
沙威玛_LHE14 小时前
树和二叉树
数据结构·算法