Cod sursa(job #2541832)
| Utilizator | Data | 8 februarie 2020 23:04:25 | |
|---|---|---|---|
| Problema | Tablete | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 2.47 kb |
#include <iostream>
#include <fstream>
using namespace std;
long long n,m,k,i,j,nr;
int main()
{
ifstream cin ("tablete.in");
ofstream cout("tablete.out");
cin>>n>>k;
if(n%2==0 && k%2==0)
{
for(i=1; i<=n; i++)
{
for(j=1; j<=n; j++)
{
cout<<n*(i-1)+j<<' ';
}
cout<<'\n';
}
}
else if(n%2==0 && k%2==1)
{
for(i=1; i<=n; i++)
{
for(j=1; j<=1; j++)
{
if(i%2==1)
cout<<k*(i-1)+j<<' ';
else
cout<<(i-1)*k<<' ';
}
for(j=2; j<k; j++)
{
if(i%2==1)
cout<<k*(i-1)+j<<' ';
else
cout<<(i-1)*k+j<<' ';
}
for(j=k; j<=k; j++)
{
nr=i*j;
if(nr%2==0)
cout<<nr<<' ';
else
cout<<nr+1<<' ';
}
for(j=k+1; j<=n; j++)
{
cout<<k*n+(i-1)*(n-k)+(j-k)<<' ';
}
cout<<'\n';
}
}
else if(n%2==1 && k%2==1)
{
for(i=1; i<=n; i++)
{
for(j=1; j<=1; j++)
{
if(i%2==1)
cout<<k*(i-1)+j<<' ';
else
cout<<(i-1)*k<<' ';
}
for(j=2; j<k; j++)
{
if(i%2==1)
cout<<k*(i-1)+j<<' ';
else
cout<<(i-1)*k+j<<' ';
}
for(j=k; j<=k; j++)
{
nr=i*j;
if(nr%2==0)
cout<<nr<<' ';
else
cout<<nr+1<<' ';
}
for(j=k+1; j<=n; j++)
{
if(i==1 && j==k+1)
{
cout<<n*k<<' ';
}
else
cout<<k*n+(i-1)*(n-k)+(j-k)<<' ';
}
cout<<'\n';
}
}
else if(n%2==1 && k%2==0)
{
for(i=1; i<=n; i++)
{
for(j=1; j<=k; j++)
cout<<(i-1)*k+j<<' ';
for(j=k+1; j<=n; j++)
cout<<n*k+(i-1)*(n-k)+(j-k)<<' ';
cout<<'\n';
}
}
return 0;
}
