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

#include<iostream>
#include<algorithm>
using namespace std;
int map[4][4]={1,1,0,0,1,1,0,0,0,0,1,1,0,0,1,1}; 
int main()
{
    int w,h;
    int a,b,c,d; 
    while(cin>>w>>h)
    {
        a=(w/4)*(h/4)*8;  //第一象限 
        b=(w%4)*(h/4)*2;        //第二象限
        c=(h%4)*(w/4)*2;         //第三象限
        d=0;
        for(int i=0;i<(w%4);i++)
        {
            for(int j=0;j<(h%4);j++)
            {
                if(map[i][j])
                {
                    d++;
                }
            }
        }
        cout<<a+b+c+d<<endl;        
    }
    return 0;    
} 
Last modification:September 20th, 2019 at 11:29 pm
如果觉得我的文章对你有用,请随意赞赏