网易编程—不要二 有时候就喜欢刚正面,暴力解

来源:互联网 发布:广联达软件客服电话 编辑:程序博客网 时间:2024/06/08 06:01
二货小易有一个W*H的网格盒子,网格的行编号为0~H-1,网格的列编号为0~W-1。每个格子至多可以放一块蛋糕,任意两块蛋糕的欧几里得距离不能等于2。
对于两个格子坐标(x1,y1),(x2,y2)的欧几里得距离为:
( (x1-x2) * (x1-x2) + (y1-y2) * (y1-y2) ) 的算术平方根
小易想知道最多可以放多少块蛋糕在网格盒子里。 
输入描述:
每组数组包含网格长宽W,H,用空格分割.(1 ≤ W、H ≤ 1000)


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

输入例子:
3 2

输出例子:
4
#include <iostream>#include <vector>#include<set>#include<cstring>//#include<unordered_map>//#include <algorithm>//#include<queue>using namespace std;int a[1000][1000];int main(){int w,h;cin >> w >> h;memset(a, 0, sizeof(a));a[0][0] = 1;int count = 0;for (int i = 0; i < h; i++){for (int j = 0; j <w; j++){if (a[i][j] == 1){count++;if(i-2>=0) a[i - 2][j] = -1; if (j+2<w) a[i][j+2] = -1; if (i+2<h) a[i+2][j] = -1; if (j-2>=0) a[i][j-2] = -1; }else if (a[i][j] == -1){continue;}else{a[i][j] = 1;if (i - 2 >= 0) a[i - 2][j] = -1;if (j + 2<w) a[i][j + 2] = -1;if (i + 2<h) a[i + 2][j] = -1;if (j - 2 >= 0) a[i][j - 2] = -1;count++;}}}cout << count << endl;//system("pause");return 0;}


0 0