-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathminswaptogroupall.c
More file actions
40 lines (32 loc) · 862 Bytes
/
minswaptogroupall.c
File metadata and controls
40 lines (32 loc) · 862 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
#include <stdio.h>
#define Max(a, b) (a > b ? a : b)
int main()
{
int t, n, i, total, current, max, l;
scanf("%d", &t);
while(t--)
{
scanf("%d", &n);
char knights[n + 1];
scanf("%s", &knights);
total = 0;
for (i = 0; i < n; i++)
{
if (knights[i] == 'K') { total++; }
}
current = 0;
for (i = 0; i < total; i++)
{
if (knights[i] == 'K') { current++; }
}
max = current;
l = n + total;
for ( ; i < l; i++)
{
if (knights[i % n] == 'K') { current++; }
if (knights[i - total] == 'K') { current--; }
max = Max(max, current);
}
printf("%d\n", total - max);
}
}