-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathP696.cpp
51 lines (48 loc) · 836 Bytes
/
P696.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <iostream>
#include <stdio.h>
using namespace std;
void handleKnight(int w, int h) {
int ret = ((w+1)/2)*((h+1)/2) + (w/2)*(h/2);
if(w == 1)
ret = h;
else if(h == 1)
ret = w;
else if(w == 2) {
switch(h%4) {
case 0:
ret = 4*(h/4);
break;
case 1:
ret = 4*(h/4)+2;
break;
case 2:
case 3:
ret = 4*(h/4)+4;
break;
}
}
else if(h == 2) {
switch(w%4) {
case 0:
ret = 4*(w/4);
break;
case 1:
ret = 4*(w/4)+2;
break;
case 2:
case 3:
ret = 4*(w/4)+4;
break;
}
}
cout << ret << " knights may be placed on a " << w << " row " << h << " column board." << endl;
}
int main() {
int w, h;
while(true) {
cin >> w >> h;
if(w == 0 && h == 0)
return 0;
handleKnight(w, h);
}
}