-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEDSTGRID.c
64 lines (54 loc) · 864 Bytes
/
EDSTGRID.c
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
#include<stdio.h>
#include<stdlib.h>
int N,M,C2,C3,black[10005][2],white[10005][2],b,w;
char str[105][105];
int main(void)
{
int T,i,j;
scanf("%d",&T);
while(T--)
{
b=0,w=0;
scanf(" %d%d%d%d",&N,&M,&C2,&C3);
for(i=1;i<=N;i++)
scanf(" %s",str[i]);
for(i=1;i<=N;i++)
{
for(j=0;j<M;j++)
{
if(str[i][j]=='B')
{
b++;
black[b][0]=i;
black[b][1]=j;
}
if(str[i][j]=='W')
{
w++;
white[w][0]=i;
white[w][1]=j;
}
}
}
int cost1,cost2,cost;
cost1=w*C2;
cost2=b*C3;
if(cost1>cost2)
cost=cost2;
else
cost=cost1;
if(cost==cost1)
{
printf("%d\n",w);
for(i=1;i<=w;i++)
printf("2 %d %d\n",white[i][0],white[i][1]+1);
}
else
{
printf("%d\n",b);
for(i=1;i<=b;i++)
printf("3 %d %d\n",black[i][0],black[i][1]+1);
}
}
return 0;
}