Pagini recente » Cod sursa (job #2738256) | Cod sursa (job #2376484) | Cod sursa (job #1755626) | Cod sursa (job #80947) | Cod sursa (job #2030357)
#include <fstream>
using namespace std;
ifstream cin("tablete.in");
ofstream cout("tablete.out");
int mat[1005][1005];
bool ap[1000*1000+5];
int main()
{
int n,k;
cin>>n>>k;
if(n%2==0)
{
if(k%2==0)
{
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
cout<<n*(i-1)+j<<" ";
cout<<"\n";
}
return 0;
}
for(int i=1;i<=n;i+=2)
{
///i i+1
for(int j=1;j<=k;j++)
cout<<(i-1)*n+j+1<<" ";
for(int j=1;j<=n-k;j++)
cout<<i*n+k+j<<" ";
cout<<"\n";
cout<<(i-1)*n+1<<" ";
for(int j=1;j<n;j++)
cout<<(i-1)*n+k+j+1<<" ";
cout<<"\n";
}
return 0;
}
if(k%2==0){
for(int i=1;i<=n;i++)
{
if(i%2==1)
mat[i][k]=n*(i-1)+k;
else
mat[i][k]=n*(i-1)+k+1;
ap[mat[i][k]]++;
}
for(int i=1;i<=n;i++)
{
int last=1;
while(ap[last]==1)
last++;
for(int j=1;j<k;j++)
{
mat[i][j]=last;
ap[last]=1;
while(ap[last]==1)
last++;
}
last=mat[i][k]+1;
while(ap[last]==1)
last++;
for(int j=k+1;j<=n;j++)
{
mat[i][j]=last;
ap[last]=1;
while(ap[last]==1)
last++;
}
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
cout<<mat[i][j]<<" ";
cout<<"\n";
}
}
for(int i=1;i<=n;i++)
{
if(i%2==0)
mat[i][k]=n*(i-1)+k;
else
mat[i][k]=n*(i-1)+k+1;
ap[mat[i][k]]++;
}
for(int i=1;i<=n;i++)
{
int last=1;
while(ap[last]==1)
last++;
for(int j=1;j<k;j++)
{
mat[i][j]=last;
ap[last]=1;
while(ap[last]==1)
last++;
}
last=mat[i][k]+1;
while(ap[last]==1)
last++;
for(int j=k+1;j<=n;j++)
{
mat[i][j]=last;
ap[last]=1;
while(ap[last]==1)
last++;
}
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
cout<<mat[i][j]<<" ";
cout<<"\n";
}
return 0;
}
/**
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
16 17 18 19 20
21 22 23 24 25
*
1 2 3 4 5
6 7 8 10 11
9 12 13 14 15
*
1 2 3 4 5
6 8 9 10 11
7 12 13 14 15
16 18 19 20 21
17 22 23 24 25
**/