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);
}
相关推荐
Dave.B14 分钟前
用【vtk3DLinearGridCrinkleExtractor】快速提取3D网格相交面
算法·3d·vtk
yaoh.wang21 分钟前
力扣(LeetCode) 1: 两数之和 - 解法思路
python·程序人生·算法·leetcode·面试·跳槽·哈希算法
又是忙碌的一天24 分钟前
二叉树的构建与增删改查(2) 删除节点
数据结构
Code Slacker38 分钟前
LeetCode Hot100 —— 滑动窗口(面试纯背版)(四)
数据结构·c++·算法·leetcode
brave and determined42 分钟前
CANN训练营 学习(day8)昇腾大模型推理调优实战指南
人工智能·算法·机器学习·ai实战·昇腾ai·ai推理·实战记录
总爱写点小BUG1 小时前
打印不同的三角形(C语言)
java·c语言·算法
yaoh.wang1 小时前
力扣(LeetCode) 27: 移除元素 - 解法思路
python·程序人生·算法·leetcode·面试·职场和发展·双指针
2401_841495642 小时前
【自然语言处理】中文 n-gram 词模型
人工智能·python·算法·自然语言处理·n-gram·中文文本生成模型·kneser-ney平滑
San302 小时前
从零到一:彻底搞定面试高频算法——“列表转树”与“爬楼梯”全解析
javascript·算法·面试
F_D_Z2 小时前
最长连续序列(Longest Consecutive Sequence)
数据结构·算法·leetcode