Cod sursa(job #230646)

Utilizator ErgoVicol Sergiu Constantin Ergo Data 14 decembrie 2008 10:03:15
Problema Tablete Scor 100
Compilator cpp Status done
Runda Algoritmiada 2009, Runda 1, Clasele 9-10 Marime 0.95 kb
#include <fstream>

using namespace std;

ifstream fin("tablete.in");
ofstream fout("tablete.out");

#define NMAX 1001

int A[NMAX*NMAX];

int main()
{
        int B[NMAX][NMAX],k,i,n,c,j,l;

        fin>>n>>k;

        for (i=1;i<=n;i++)
        {
                c=k*i;
                if (c%2!=0) c++;
                A[c]=1;
                B[i][k]=c;
        }
        l=1;
        int g;
        for (i=1;i<=n;i++)
                for (j=1;j<k;j++)
                        for (g=0;g==0;l++)
                                if (A[l]==0) B[i][j]=l,A[l]=1,g=1;



        for (i=1;i<=n;i++)
                for (j=k+1;j<=n;j++)
                        for (g=0;g==0;l++)
                                if (A[l]==0) B[i][j]=l,A[l]=1,g=1;

                                
        for (i=1;i<=n;i++)
        {
                for (j=1;j<=n;j++)
                        fout<<B[i][j]<<' ';
                fout<<'\n';
        }
        fout.close();
        return 0;
}