不要

二货小易有一个W*H的网格盒子,网格的行编号为0H-1,网格的列编号为0W-1。每个格子至多可以放一块蛋糕,任意两块蛋糕的欧几里得距离不能等于2。
对于两个格子坐标(x1,y1),(x2,y2)的欧几里得距离为:
( (x1-x2) * (x1-x2) + (y1-y2) * (y1-y2) ) 的算术平方根
小易想知道最多可以放多少块蛋糕在网格盒子里。

输入描述:
每组数组包含网格长宽W,H,用空格分割.(1 ≤ W、H ≤ 1000)

输出描述:
输出一个最多可以放的蛋糕数

示例1
输入
3 2
输出
4

#include<iostream>
using namespace std;
int main()
{
    int lie,hang;
    cin >> lie >> hang;
    int res = 0;
    int temp;
    for(int i = 1;i <= hang;i++)
    {
        if(i % 4 == 1 || i % 4 == 2)
        {
            res += (lie / 4) * 2;
            temp = lie % 4;
            if(temp == 1)res+=1;
            else if(temp == 2 || temp == 3) res+=2;
        }
        else
        {
            res += (lie / 4) * 2;
            temp = lie % 4;
            if(temp == 3)res++;
        }
    }
    
    cout << res;
}

猜你喜欢

转载自blog.csdn.net/weixin_40936298/article/details/82899661