Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #define Nmax 102
- using namespace std;
- int a[Nmax][Nmax],C,E,cr,el;
- const int dx[]={0, 0,1,-1},
- dy[]={1,-1,0, 0};
- void umple(int i,int j,int val)
- {
- a[i][j]=val;
- if(val==2)
- ++cr;
- else
- ++el;
- for(int k=0;k<4;++k)
- if(a[i+dx[k]][j+dy[k]]==0)
- {
- if(val==2)
- umple(i+dx[k],j+dy[k],3);
- else
- umple(i+dx[k],j+dy[k],2);
- }
- }
- int main()
- {
- ifstream f("croco1.in");
- int n,m;
- f>>n>>m;
- for(int i=1;i<=n;++i)
- for(int j=1;j<=m;++j)
- f>>a[i][j];
- f.close();
- for(int i=0;i<=n+1;++i) /// Bordare
- a[i][0]=a[i][m+1]=1;
- for(int j=0;j<=m+1;++j)
- a[0][j]=a[n+1][j]=1;
- for(int i=1;i<=n;++i)
- for(int j=1;j<=m;++j)
- if(a[i][j]==0)
- {
- cr=0,el=0;
- umple(i,j,2);
- if(cr<el)
- swap(cr,el);
- C+=cr,E+=el;
- }
- ofstream g("croco1.out");
- g<<C<<' '<<E;
- g.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement