Pagini recente » Cod sursa (job #2964717) | Cod sursa (job #2291652) | Cod sursa (job #2092073) | Cod sursa (job #377605) | Cod sursa (job #1059609)
#include <fstream>
#include <algorithm>
#define maxn 301
using namespace std;
ifstream fin("grozavesti.in");
ofstream fout("grozavesti.out");
struct field
{
int x,i,j;
}v[maxn*maxn];
int row[maxn],col[maxn];
int invrow[maxn],invcol[maxn];
char s[maxn*2];
int sol1[maxn*2],sol2[maxn*2];
int n,t;
bool cmp (const field &a, const field &b)
{
return a.x < b.x;
}
int main()
{
fin>>n;
for (int i=1; i<=n; ++i)
for (int j=1; j<=n; ++j)
{
++t;
fin>>v[t].x;
v[t].i = i;
v[t].j = j;
}
for (int i=1; i<=n; ++i)
{
row[i] = i;
invrow[i] = i;
col[i] = i;
invcol[i] = i;
}
sort (v+1,v+t+1,cmp);
t=0;
for (int i=1,j=1; i<=n; ++i)
{
while (row[v[j].i] < i || col[v[j].j] < i) ++j;
if (row[v[j].i] != i)
{
++t;
s[t] = 'L';
sol1[t] = row[v[j].i];
sol2[t] = i;
swap (row[v[j].i],row[invrow[i]]);
swap (invrow[row[v[j].i]],invrow[i]);
}
if (col[v[j].j] != i)
{
++t;
s[t] = 'C';
sol1[t] = col[v[j].j];
sol2[t] = i;
swap (col[v[j].j],col[invcol[i]]);
swap (invcol[col[v[j].j]],invcol[i]);
}
}
fout<<t<<"\n";
for (int i=1; i<=t; ++i)
{
fout<<s[i]<<" "<<sol1[i]<<" "<<sol2[i]<<"\n";
}
}