Cod sursa(job #1180306)

Utilizator DenisONIcBanu Denis Andrei DenisONIc Data 30 aprilie 2014 14:51:06
Problema Tablete Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.86 kb
#include <fstream>
using namespace std;
ifstream f("tablete.in");
ofstream g("tablete.out");
long x,n,k,i,j,mat[1001][1001];
bool v[1000001];
int main()
{
    f>>n>>k;
    for (i=1;i<=n;i++)
    {
        x=k*i;
        if (x%2==1)
            x++;
        while (v[x]==1)
            x+=2;
        mat[i][k]=x;
        v[x]=1;
    }
    x=1;
    for (i=1;i<=n;i++)
        for (j=1;j<=k-1;j++)
        {
            while (v[x]==1)
                x++;
            mat[i][j]=x;
            v[x]=1;
        }
    for (i=1;i<=n;i++)
        for (j=k+1;j<=n;j++)
        {
            while(v[x]==1)
                x++;
            mat[i][j]=x;
            v[x]=1;
        }
    for (i=1;i<=n;i++)
    {
        for (j=1;j<=n;j++)
            g<<mat[i][j]<<' ';
        g<<'\n';
    }
    f.close();
    g.close();
    return 0;
}