Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<fstream>
- using namespace std;
- ifstream fin("pion.in");
- ofstream fout("pion.out");
- int n,i,j, a[50][50], c[50][50];
- void citire()
- { int i,j;
- fin>>n;
- for(i=1;i<=n;i++)
- for(j=1;j<=n;j++) fin>>a[i][j];
- }
- void pd()
- { int i,j;
- for(i=2;i<=n;i++)
- for(j=1;j<=n;j++)
- if(a[i][j]==0)
- c[i][j]=c[i-1][j];
- else if(c[i-1][j-1]>c[i-1][j+1])
- c[i][j]=c[i-1][j-1]+1;
- else c[i][j]=c[i-1][j+1]+1;
- }
- void drum(int i, int j)
- {
- if(i==1) fout<<i<<" "<<j<<endl;
- else { if(a[i][j]==0) drum(i-1,j);
- else if(c[i-1][j-1]+1==c[i][j])
- drum(i-1,j-1);
- else drum(i-1,j+1);
- fout<<i<<" "<<j<<endl;
- }
- }
- void afis()
- {
- int max=0,jm;
- for(j=1;j<=n;j++) if(c[n][j]>max) { max=c[n][j]; jm=j; }
- fout<<max<<endl;
- drum(n,jm);
- }
- int main()
- { citire();
- pd();
- afis();
- fin.close();
- fout.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement