Cod sursa(job #3255571)

Utilizator Carnu_EmilianCarnu Emilian Carnu_Emilian Data 11 noiembrie 2024 10:40:56
Problema Grozavesti Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.19 kb
#include<bits/stdc++.h>
using namespace std;
ifstream fcin("grozavesti.in");
ofstream fcout("grozavesti.out");

const int N = 305;
int v[N][N];
int n, ncop;

struct com
{
    char c;
    int x, y;
};
vector<com> r;

void swapCol(int j1, int j2)
{
    for (int i = 1; i <= n; i++)
        swap(v[i][j1], v[i][j2]);
    r.push_back({'C', j1, j2});
}
void swapLin(int i1, int i2)
{
    for (int j = 1; j <= n; j++)
        swap(v[i1][j], v[i2][j]);
    r.push_back({'L', i1, i2});
}

void f()
{
    if (n == 1) return;
    int maxx, imax, jmax;
    maxx = 0;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
            if (v[i][j] >= maxx)
            {
                maxx = v[i][j];
                imax = i;
                jmax = j;
            }
    if (jmax != n)
        swapCol(jmax, n);
    if (imax != n)
        swapLin(imax, n);
    n--;
    f();
}

int main()
{
    fcin >> ncop;
    n = ncop;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
            fcin >> v[i][j];
    f();
    fcout << r.size() << '\n';
    for (com e : r)
        fcout << e.c << ' ' << e.x << ' ' << e.y << '\n';
    return 0;
}