Pagini recente » Cod sursa (job #3332947) | Cod sursa (job #3335028) | Cod sursa (job #3333578) | Cod sursa (job #3352180) | Cod sursa (job #3334919)
#include <fstream>
#include <algorithm>
using namespace std;
ifstream cin("tablete.in");
ofstream cout("tablete.out");
int a[1005][1005];
int main()
{
int n, k;
cin >> n >> k;
if(k%2==0)
{
for(int x=1;x<=n;x++)
{
for(int j=1;j<=n;j++)
{
a[x][j]=n*x+j;
}
}
}
else
{
if(n%2==0)
{
for(int x=1;x<n;x++)
{
a[1][x]=x+1;
}
a[1][n]=2*n;
a[2][1]=1;
for(int x=2;x<n;x++)
{
a[2][x]=a[1][x]+n-2;
}
a[2][n]=2*n-1;
for(int x=3;x<=n;x++)
{
for(int j=1;j<=n;j++)
{
a[x][j]=a[x-2][j]+2*n;
}
}
}
else
{
for(int x=1;x<=n;x++)
{
a[1][x]=x+1;
}
a[2][1]=1;
for(int x=2;x<=n;x++)
{
a[2][x]=a[1][x]+n-1;
}
for(int x=3;x<=n-2;x++)
{
for(int j=1;j<=n;j++)
{
a[x][j]=a[x-2][j]+2*n;
}
}
for(int j=1;j<n;j++)
{
a[n-1][j]=a[n-3][j]+2*n;
}
a[n-1][n]=n*n;
for(int j=1;j<=n;j++)
{
a[n][j]=n*(n-1)+j-1;
}
}
}
for(int x=1;x<=n;x++)
{
for(int j=1;j<=n;j++)
{
cout << a[x][j] << " ";
}
cout << '\n';
}
return 0;
}