forked from Nimesh-Srivastava/DSA
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconflip.c
More file actions
44 lines (40 loc) · 863 Bytes
/
conflip.c
File metadata and controls
44 lines (40 loc) · 863 Bytes
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
#include <stdio.h>
int main(void)
{
int t;
scanf("%d", &t);
while(t--)
{
int g;
scanf("%d", &g);
for (int j=0; j<g; j++)
{
int i, n, q;
scanf("%d%d%d", &i, &n, &q);
int heads = 0;
int tails = 0;
if(n%2 == 0)
{
heads = tails = n/2;
}
else
{
if(i==1)
{
tails = (n+1) / 2;
heads = (n-1) / 2;
}
else
{
heads = (n+1) / 2;
tails = (n-1) / 2;
}
}
if (q==1)
printf("%d\n", heads);
else
printf("%d\n", tails);
}
}
return 0;
}