Cod sursa(job #1695014)

Utilizator tziplea_stefanTiplea Stefan tziplea_stefan Data 26 aprilie 2016 14:21:54
Problema Piese Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.9 kb
#include <fstream>
#define VAL 505

using namespace std;

ifstream fin("piese.in");
ofstream fout("piese.out");

int N, M, i, j;
int cnt1, cnt2;
int v[VAL][VAL];
int l, best, mn;

int main()
{
    fin >> N >> M;
    for (i=1; i<=N; i++)
    {
        for (j=1; j<=M; j++)
        {
            if (v[i][j]==0)
            {
                l=1;
                while (i+l-1<=N && j+l-1<=M)
                {
                    best=l;
                    l*=2;
                }
                mn++;
                for (cnt1=i; cnt1<=i+best-1; cnt1++)
                  for (cnt2=j; cnt2<=j+best-1; cnt2++)
                    v[cnt1][cnt2]=mn;
            }
        }
    }
    fout << mn << '\n';
    for (i=1; i<=N; i++)
    {
        for (j=1; j<=M; j++)
          fout << v[i][j] << " ";
        fout << '\n';
    }
    fin.close();
    fout.close();
    return 0;
}