Cod sursa(job #110806)

Utilizator rethosPaicu Alexandru rethos Data 27 noiembrie 2007 20:07:41
Problema Lacate Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.6 kb
#include <fstream.h>
#define max 256
#define comb max*(max+1)/2
int a[comb][max],viz[comb];
int main()
{ int n,i,j,k,c,x;
  ifstream f("lacate.in");
  ofstream g("lacate.out");
  f>>n;
  f.close();
  c=n*(n-1)/2;
  g<<c<<' '<<n-1<<'\n';
  for (i=1;i<n;i++)
	a[1][i]=i;
  x=n;
  for (k=2;k<=n;k++)
	{ for (i=1;i<k;i++)
		for (j=1;j<n;j++)
			if (viz[a[i][j]]==0)
				{ viz[a[i][j]]=1;
				  a[k][i]=a[i][j];
				  break;
				}
	  for (j=k;j<n;j++)
		{ a[k][j]=x;
		  x++;
		}
	}
  for (i=1;i<=n;i++)
	{ for (j=1;j<=n-1;j++)
		g<<a[i][j]<<' ';
	  g<<'\n';
	}
  g.close();
  return 0;
}