Cod sursa(job #1879949)
Utilizator | Data | 15 februarie 2017 11:55:38 | |
---|---|---|---|
Problema | Tablete | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 1.35 kb |
#include <fstream>
using namespace std;
ifstream cin("tablete.in");
ofstream cout("tablete.out");
int n,m,k,x,i,j,v[1005][1005];
bool f[1000005];
int main()
{
cin>>n>>k;
x=n*n;
for(j=n;j>=1;j--)
{
for(i=n;i>=1;i--)
{
if(j!=k&&j!=k-1)
{
while(f[x])
x--;
v[i][j]=x;
f[x]=1;
}
else if(j==k)
{
if(v[1][j+1]%2)
{
if(i==n)
x--;
v[i][j]=x;
f[x]=1;
x-=2;
}
else
{
if(i==n)
{
v[1][j+1]--;
f[v[1][j+1]]=1;
f[v[1][j+1]+1]=0;
x=v[1][j+1]+1;
}
v[i][j]=x;
f[x]=1;
x-=2;
}
}
else if(j==k-1)
{
x=v[n][j+1];
while(f[x])
x--;
v[i][j]=x;
f[x]=1;
}
}
}
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
cout<<v[i][j]<<' ';
cout<<'\n';
}
return 0;
}