Cod sursa(job #190967)

Utilizator andrei-alphaAndrei-Bogdan Antonescu andrei-alpha Data 24 mai 2008 17:21:26
Problema Grozavesti Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.99 kb
#include <stdio.h>
#include <algorithm>
using namespace std;

#define Nmax 301
#define IN "grozavesti.in"
#define OUT "grozavesti.out"

int sol,n,v[Nmax];
struct schimbare{int a,b;};
schimbare sc[Nmax];

int main()
{
	int inj,aux,gata,x;
	freopen(IN, "r",stdin);
	freopen(OUT, "w",stdout);
	scanf("%d", &n);
	for(int i=1;i<=n;++i)
		for(int j=1;j<=n;++j)
		{
			scanf("%d", &x);
			if(i==j)
				v[i]=x;
		}
	
	inj=n;    
    while(inj>1)    
    {    
        inj/=2;    
        do{    
            gata=1;    
            for(int i=1;i<=n-inj;i++)    
                if(v[i]>v[i+inj])    
                {    
                    sc[++sol].a=i;
					sc[sol].b=i+inj;
					aux=v[i]; 
					v[i]=v[i+inj];    
                    v[i+inj]=aux;    
                    gata=0;    
                }    
        }    
        while(!gata);    
    }     	
		
		
	printf("%d\n", sol);
	for(int i=1;i<=sol;++i)
		printf("C %d %d\n",sc[i].a,sc[i].b);
	return 0;
}