Advertisement
Guest User

pb bilei

a guest
Nov 12th, 2019
337
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. #include <iostream>
  2. #include<fstream>
  3. using namespace std;
  4. int a[100][100];
  5. struct elem {
  6. int l,c;}st[100];
  7. ifstream f("date.in");
  8. void tipar(int p)
  9. {
  10. int i;
  11. cout<<endl;
  12. for(i=1;i<=p;i++)
  13. cout<<a[st[i].l][st[i].c]<<" ";
  14.  
  15. }
  16. bool valid(int p)
  17. {
  18. int ok=1,i;
  19. for(i=1;i<=p-1;i++)
  20. if(st[i].c==st[p].c && st[i].l==st[p].l)
  21. ok=0;
  22. if(a[st[p].l][st[p].c]>=a[st[p-1].l][st[p-1].c])
  23. ok=0;
  24. return ok;
  25. }
  26. int main()
  27. {
  28. int i,di[10],dj[10],d[10],p,li,ci,j,m,n;
  29. f>>li>>ci>>m>>n;
  30. for(i=1;i<=m;i++)
  31. for(j=1;j<=n;j++)
  32. f>>a[i][j];
  33. for(i=0;i<=m+1;i++)
  34. {
  35. a[i][0]=INT_MAX;
  36. a[i][n+1]=INT_MAX;
  37.  
  38. }
  39. for(i=0;i<=n+1;i++)
  40. {
  41. a[0][i]=INT_MAX;
  42. a[m+1][i]=INT_MAX;
  43.  
  44. }
  45. di[0]=-1; di[1]=0; di[2]=1; di[3]=0;
  46. dj[0]=0; dj[1]=1; dj[2]=0; dj[3]=-1;
  47. p=1;
  48. st[p].l=li;
  49. st[p].c=ci;
  50. p=2;
  51. d[p]=-1;
  52. while(p>1)
  53. {
  54. if(d[p]<3)
  55. {
  56. d[p]++;
  57. st[p].l=st[p-1].l+di[d[p]];
  58. st[p].c=st[p-1].c+dj[d[p]];
  59. if(valid(p)==1)
  60. if((st[p].l==1||st[p].c==1||st[p].l==m||st[p].c==n))
  61. {tipar(p);
  62. p=p+1;
  63. d[p]=-1;
  64.  
  65. }
  66. else{
  67. p=p+1;
  68. d[p]=-1;
  69.  
  70. }}
  71. else
  72. p=p-1;
  73.  
  74.  
  75. }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement