Cod sursa(job #782323)

Utilizator repp4raduRadu-Andrei Szasz repp4radu Data 26 august 2012 18:58:05
Problema Grozavesti Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.95 kb
#include <fstream>

#define MAX 512
#define INF 0x3f3f3f3f

using namespace std;

int c[MAX][MAX], moves[MAX][2], ind, n;

int main()
{
    ifstream in("grozavesti.in");
    in>>n;
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= n; j++)
            in>>c[i][j];
    for(int i = 1; i <= n; i++)
    {
        int minim = INF, lMin, cMin;
        for(int j = i; j <= n; j++)
        {
            if(c[j][j] < minim)
            {
                lMin = j;
                cMin = j;
                minim = c[j][j];
            }
        }
        if(lMin != i && cMin != i)
        {
            swap(c[i][i], c[lMin][cMin]);
            moves[++ind][0] = i; moves[ind][1] = lMin;
        }
    }
    ofstream out("grozavesti.out");
    out<<2 * ind<<"\n";
    for(int i = 1; i <= ind; i++)
        out<<"L "<<moves[i][0]<<" "<<moves[i][1]<<"\n"<<"C "<<moves[i][0]<<" "<<moves[i][1]<<"\n";
    out.close();

    return 0;
}