-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1010 - Knights in Chessboard.cpp
111 lines (104 loc) · 2.18 KB
/
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/**
* Author: Ashraful Islam Rafi
* University: Leading University,Sylhet
* url: http://www.lightoj.com/volume_showproblem.php?problem=1010
* problem id: 1010 - Knights in Chessboard
* complexity: 2nd level(biginers problem)
* site: Lightoj.com
**/
#include"map"
#include"set"
#include"queue"
#include"cmath"
#include"stack"
#include"ctype.h"
#include"cstdio"
#include"vector"
#include"cstdio"
#include"cstring"
#include"cstdlib"
#include"string.h"
#include"iostream"
#include"algorithm"
using namespace std;
#define cs "Case "<<++casee<<": "
#define csE "Case "<<++casee<<":\n"
#define sf(t) scanf("%d",&t)
#define sNE(n,e) scanf("%d %d",&N,&E)
#define Inf 1000000000
#define S_N 5000010
#define MST(a, tf) memset(a, tf, sizeof (a))
int main()
{
int tt,t=0,i,j,k,rw,cl,f1,f2,ans;
sf(tt); int casee=0;
while(tt--)
{
cin>>rw>>cl;
if(cl % 2==0)
{
f1=cl/2;
f2=f1;
}
else
{
f1=(cl+1)/2;
f2=f1-1;
}
if(cl==1 || rw==1)
{
ans=rw*cl;
cout<<cs<<ans<<endl; continue;
}
if(rw==2)
{
if(cl % 2==0)
{
if(cl % 4==0)
{
ans=cl;
cout<<cs<<ans<<endl; continue;
}
ans=cl+2;
cout<<cs<<ans<<endl; continue;
}
else
{
ans=cl+1;
cout<<cs<<ans<<endl; continue;
}
}
if(cl==2)
{
if(rw%2==0)
{
if(rw%4==0)
{
ans=rw;
cout<<cs<<ans<<endl; continue;
}
ans=rw+2;
cout<<cs<<ans<<endl; continue;
}
else
{
ans=rw+1;
cout<<cs<<ans<<endl; continue;
}
}
if(rw % 2==0) ans=f1*(rw/2)+f2*(rw/2);
else ans=f1 * ((rw/2)+1) + f2*(rw/2);
cout<<cs<<ans<<endl;
}
}
///---tnQss to KC.......:P---////
///---test case--//
/**
3
8 8
3 7
4 10
Case 1: 32
Case 2: 11
Case 3: 20
*/