Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include<fstream>
- using namespace std;
- int a[100][100];
- struct elem {
- int l,c;}st[100];
- ifstream f("date.in");
- void tipar(int p)
- {
- int i;
- cout<<endl;
- for(i=1;i<=p;i++)
- cout<<a[st[i].l][st[i].c]<<" ";
- }
- bool valid(int p)
- {
- int ok=1,i;
- for(i=1;i<=p-1;i++)
- if(st[i].c==st[p].c && st[i].l==st[p].l)
- ok=0;
- if(a[st[p].l][st[p].c]>=a[st[p-1].l][st[p-1].c])
- ok=0;
- return ok;
- }
- int main()
- {
- int i,di[10],dj[10],d[10],p,li,ci,j,m,n;
- f>>li>>ci>>m>>n;
- for(i=1;i<=m;i++)
- for(j=1;j<=n;j++)
- f>>a[i][j];
- for(i=0;i<=m+1;i++)
- {
- a[i][0]=INT_MAX;
- a[i][n+1]=INT_MAX;
- }
- for(i=0;i<=n+1;i++)
- {
- a[0][i]=INT_MAX;
- a[m+1][i]=INT_MAX;
- }
- di[0]=-1; di[1]=0; di[2]=1; di[3]=0;
- dj[0]=0; dj[1]=1; dj[2]=0; dj[3]=-1;
- p=1;
- st[p].l=li;
- st[p].c=ci;
- p=2;
- d[p]=-1;
- while(p>1)
- {
- if(d[p]<3)
- {
- d[p]++;
- st[p].l=st[p-1].l+di[d[p]];
- st[p].c=st[p-1].c+dj[d[p]];
- if(valid(p)==1)
- if((st[p].l==1||st[p].c==1||st[p].l==m||st[p].c==n))
- {tipar(p);
- p=p+1;
- d[p]=-1;
- }
- else{
- p=p+1;
- d[p]=-1;
- }}
- else
- p=p-1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement