網易2017內推筆試程式設計題合集(二)(第三題) 不要二
阿新 • • 發佈:2019-02-14
[程式設計題] 不要二
二貨小易有一個W*H的網格盒子,網格的行編號為0~H-1,網格的列編號為0~W-1。每個格子至多可以放一塊蛋糕,任意兩塊蛋糕的歐幾里得距離不能等於2。
對於兩個格子座標(x1,y1),(x2,y2)的歐幾里得距離為:
( (x1-x2) * (x1-x2) + (y1-y2) * (y1-y2) ) 的算術平方根
小易想知道最多可以放多少塊蛋糕在網格盒子裡。
對於兩個格子座標(x1,y1),(x2,y2)的歐幾里得距離為:
( (x1-x2) * (x1-x2) + (y1-y2) * (y1-y2) ) 的算術平方根
小易想知道最多可以放多少塊蛋糕在網格盒子裡。
輸入描述:
每組陣列包含網格長寬W,H,用空格分割.(1 ≤ W、H ≤ 1000)
輸出描述:
輸出一個最多可以放的蛋糕數
輸入例子:
3 2
輸出例子:
4
#include<iostream> #include<cstring> #include<vector> #include<algorithm> using namespace std; int num[51][32]; int main(){ int n,m; cin>>n>>m; int nn = n / 4 * 2; if(n % 4 == 1) nn++; if(n % 4 >= 2) nn+=2; int ans = m / 4 * n * 2; if( m % 4 == 1) ans += nn; if( m % 4 == 2) ans += nn * 2; if( m % 4 == 3) ans += nn + n; cout<<ans<<endl; }