Advertisement
a53

Croco1

a53
Jan 2nd, 2018
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. #include <fstream>
  2. #define Nmax 102
  3. using namespace std;
  4. int a[Nmax][Nmax],C,E,cr,el;
  5. const int dx[]={0, 0,1,-1},
  6. dy[]={1,-1,0, 0};
  7.  
  8. void umple(int i,int j,int val)
  9. {
  10. a[i][j]=val;
  11. if(val==2)
  12. ++cr;
  13. else
  14. ++el;
  15. for(int k=0;k<4;++k)
  16. if(a[i+dx[k]][j+dy[k]]==0)
  17. {
  18. if(val==2)
  19. umple(i+dx[k],j+dy[k],3);
  20. else
  21. umple(i+dx[k],j+dy[k],2);
  22. }
  23. }
  24.  
  25. int main()
  26. {
  27. ifstream f("croco1.in");
  28. int n,m;
  29. f>>n>>m;
  30. for(int i=1;i<=n;++i)
  31. for(int j=1;j<=m;++j)
  32. f>>a[i][j];
  33. f.close();
  34. for(int i=0;i<=n+1;++i) /// Bordare
  35. a[i][0]=a[i][m+1]=1;
  36. for(int j=0;j<=m+1;++j)
  37. a[0][j]=a[n+1][j]=1;
  38. for(int i=1;i<=n;++i)
  39. for(int j=1;j<=m;++j)
  40. if(a[i][j]==0)
  41. {
  42. cr=0,el=0;
  43. umple(i,j,2);
  44. if(cr<el)
  45. swap(cr,el);
  46. C+=cr,E+=el;
  47. }
  48. ofstream g("croco1.out");
  49. g<<C<<' '<<E;
  50. g.close();
  51. return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement