forked from hackerkid/LightOJ-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
1010-Knights-In-Chessboard.cpp
88 lines (52 loc) · 989 Bytes
/
1010-Knights-In-Chessboard.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <iostream>
#include <stdio.h>
using namespace std;
int cal(int row, int col)
{
int col1;
int col2;
int row1;
int row2;
int ans;
int temp;
row1 = (row / 2) + (row % 2);
row2 = (row / 2);
col1 = (col / 2) + (col % 2);
col2 = col / 2;
ans = row1 * col1 + row2 * col2;
return ans;
}
int two(int row, int col)
{
int ans;
int temp;
temp = cal(row, col);
row = max(row, col);
ans = (row / 4) * 4 + min(2, row % 4) * 2;
ans = max(ans, temp);
return ans;
}
int main()
{
int t;
int row;
int col;
scanf("%d", &t);
for (int cs = 1; cs <= t; cs++) {
scanf("%d", &row);
scanf("%d", &col);
if(row == 1 or col == 1) {
printf("Case %d: %d\n", cs, max(row, col));
continue;
}
if(row == 2 or col == 2) {
printf("Case %d: %d\n", cs, two(row, col));
continue;
}
if(min(row, col) == 2 and max(row, col) == 3) {
printf("Case %d: 4\n", cs);
continue;
}
printf("Case %d: %d\n", cs, cal(row, col));
}
}