Cod sursa(job #983321)

Utilizator dariusdariusMarian Darius dariusdarius Data 11 august 2013 15:42:25
Problema Tablete Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.25 kb
#include<cstdio>
#include<algorithm>
using namespace std;
void solve_par_par(int n,int k)
{
    for(int i=1;i<=n*n;i++)
        printf("%d%c",i,i%n==0?'\n':' ');
}
void solve_par_impar(int n,int k)
{
    for(int i=1;i<=n;i++)
        if(i%2==1)
        {
            for(int j=1;j<k;j++)
                printf("%d ",j+(i-1)*k);
            printf("%d",k+1+(i-1)*k);
            for(int j=k+1;j<=n;j++)
                printf(" %d",(i-2)*k+n*k+j);
            printf("\n");
        }
        else
        {
            printf("%d",k+(i-2)*k);
            for(int j=2;j<=k;j++)
                printf(" %d",j+k+(i-2)*k);
            for(int j=k+1;j<=n;j++)
                printf(" %d",(i-2)*(n-k)+n*k+j);
            printf("\n");
        }
}
void solve_impar_impar(int n,int k)
{

}
void solve_impar_par(int n,int k)
{

}
int main()
{
    freopen("tablete.in","r",stdin);
    freopen("tablete.out","w",stdout);
    int n,k;
    scanf("%d%d",&n,&k);
    if(n%2==0 && k%2==0)
    {
        solve_par_par(n,k);
        return 0;
    }
    if(n%2==0 && k%2==1)
    {
        solve_par_impar(n,k);
        return 0;
    }
    if(k%2==0)
        solve_impar_par(n,k);
    else
        solve_impar_impar(n,k);
    return 0;
}