Cod sursa(job #851173)

Utilizator stoicatheoFlirk Navok stoicatheo Data 9 ianuarie 2013 17:32:39
Problema Strazi Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.01 kb
#include<fstream>
#include<vector>
#define dmax 510
using namespace std;
 
int n,m;
int put[15],nr;
int a[dmax][dmax];
 
 
void citire()
{
 ifstream fin("piese.in");
  
 fin>>n>>m;
  
 fin.close();
}
 
 
int acoperire(int h, int w, int x, int y)
{
 int i=0,j,k,t1=0,t2=0;
  
 while (put[i] <= h && put[i] <= w)
     i++;
 i--;
  
 nr++;
 for (j=x; j<x + put[i]; j++)
     for (k=y; k<y + put[i]; k++)
         a[j][k] = nr;
  
 if (put[i] < h)
     t1 = acoperire(h-put[i], put[i], x+put[i], y);
  
 if (put[i] < w)
     t2 = acoperire(h, w-put[i], x, y+put[i]);
  
 return t1+t2+1;
}
 
 
void afisare()
{
 int i,j;
     
 ofstream fout("piese.out");
  
 fout<<acoperire(n,m,1,1)<<'\n';
  
 for (i=1; i<=n; i++)
     {
      for (j=1; j<=m; j++)
          fout<<a[i][j]<<" ";
      fout<<'\n';
     }
  
 fout.close();
}
 
 
int main()
{
 int i;
     
 citire();
  
 put[0] = 1;
 for (i=1; i<=10; i++)
     put[i] = put[i-1] * 2;
  
 afisare();
     
 return 0;
}