#include<bits/stdc++.h>
using namespace std;
int pole[3006][3006];
int tab1[6006][300];
int h[6006][2];
int main()
{
int x, y, C=3003, ht=0;
cin >> x >> y;
for(int i=0; i<x; i++)
{
for(int j=0; j<y; j++)
{
char Y;
cin >> Y;
tab1[i][(int)Y]++;
tab1[j+C][(int)Y]++;
pole[i][j]=(int)Y;
}
}
int G=1;
while(G==1)
{
G=0;
for(int i=0; i<6005; i++)
{
int G1=0;
for(int j=64; j<91; j++)
{
if(tab1[i][j]>0)
{
G=1;
if(G1==0)
{G1=j;}
else
{G1=-1;}
}
}
if(G1>0)
{
h[ht][0]=i; h[ht][1]=G1; tab1[i][G1]=0; ht++;
for(int p=0; p<3003; p++)
{
if(i>=C)
{
if(pole[p][i-C]==G1)
{tab1[p][G1]--;}
}
else
{
if(pole[i][p]==G1)
{tab1[p+C][G1]--;}
}
}
}
}
}
cout << ht << "\n";
for(int i=ht-1; i>=0; i--)
{
if(h[i][0]>=C)
{cout << "K " << h[i][0]-C+1 << " " << (char)h[i][1] << "\n";}
else
{cout << "R " << h[i][0]+1 << " " << (char)h[i][1] << "\n";}
}
}
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 | #include<bits/stdc++.h> using namespace std; int pole[3006][3006]; int tab1[6006][300]; int h[6006][2]; int main() { int x, y, C=3003, ht=0; cin >> x >> y; for(int i=0; i<x; i++) { for(int j=0; j<y; j++) { char Y; cin >> Y; tab1[i][(int)Y]++; tab1[j+C][(int)Y]++; pole[i][j]=(int)Y; } } int G=1; while(G==1) { G=0; for(int i=0; i<6005; i++) { int G1=0; for(int j=64; j<91; j++) { if(tab1[i][j]>0) { G=1; if(G1==0) {G1=j;} else {G1=-1;} } } if(G1>0) { h[ht][0]=i; h[ht][1]=G1; tab1[i][G1]=0; ht++; for(int p=0; p<3003; p++) { if(i>=C) { if(pole[p][i-C]==G1) {tab1[p][G1]--;} } else { if(pole[i][p]==G1) {tab1[p+C][G1]--;} } } } } } cout << ht << "\n"; for(int i=ht-1; i>=0; i--) { if(h[i][0]>=C) {cout << "K " << h[i][0]-C+1 << " " << (char)h[i][1] << "\n";} else {cout << "R " << h[i][0]+1 << " " << (char)h[i][1] << "\n";} } } |
English