Advertisement
Guest User

spaghett

a guest
Mar 23rd, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.68 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <vector>
  4. #include <tuple>
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     ifstream fin("schior.in");
  10.     ofstream fout("schior.out");
  11.     int maxx,maxy,startx,starty;
  12.     fin>>maxy;fin>>maxx;
  13.     fin>>starty;fin>>startx;
  14.     int harta[maxx][maxy];
  15.     bool checked[maxx][maxy];
  16.     for(int y=0;y<maxy;y++)
  17.     {
  18.         for(int x=0;x<maxx;x++)
  19.         {
  20.             fin>>harta[x][y];
  21.             checked[x][y]=false;
  22.         }
  23.     }
  24.     vector<tuple<int,int,int>> last,curr;
  25.     last.push_back(make_tuple(harta[startx-1][starty-1],startx-1,starty-1));
  26.     while(!last.empty())
  27.     {
  28.         //push_heap(last.begin(),last.end());
  29.         curr.clear();
  30.         for(auto i : last)
  31.         {
  32.             int alti=get<0>(i), x=get<1>(i), y=get<2>(i);
  33.             checked[x][y]=true;
  34.             if(x>0){
  35.                 if(y>0)
  36.                 {
  37.                     if(!checked[x-1][y-1]&&harta[x-1][y-1]<=alti){
  38.                         curr.push_back(make_tuple(harta[x-1][y-1],x-1,y-1));
  39.                     }
  40.                 }
  41.                 if(!checked[x-1][y]&&harta[x-1][y]<=alti){
  42.                         curr.push_back(make_tuple(harta[x-1][y],x-1,y));
  43.                     }
  44.                 if(y<maxy-1)
  45.                 {
  46.                     if(!checked[x-1][y+1]&&harta[x-1][y+1]<=alti){
  47.                         curr.push_back(make_tuple(harta[x-1][y+1],x-1,y+1));
  48.                     }
  49.                 }
  50.             }
  51.             if(x<maxx-1){
  52.                 if(y>0)
  53.                 {
  54.                     if(!checked[x+1][y-1]&&harta[x+1][y-1]<=alti){
  55.                         curr.push_back(make_tuple(harta[x+1][y-1],x+1,y-1));
  56.                     }
  57.                 }
  58.                 if(!checked[x+1][y]&&harta[x+1][y]<=alti){
  59.                         curr.push_back(make_tuple(harta[x+1][y],x+1,y));
  60.                     }
  61.                 if(y<maxy-1)
  62.                 {
  63.                     if(!checked[x+1][y+1]&&harta[x+1][y+1]<=alti){
  64.                         curr.push_back(make_tuple(harta[x+1][y+1],x+1,y+1));
  65.                     }
  66.                 }
  67.             }
  68.             if(y>0){
  69.                     if(!checked[x][y-1]&&harta[x][y-1]<=alti){
  70.                         curr.push_back(make_tuple(harta[x][y-1],x,y-1));
  71.                     }
  72.             }
  73.             if(y<maxy-1){
  74.                     if(!checked[x][y+1]&&harta[x][y+1]<=alti){
  75.                         curr.push_back(make_tuple(harta[x][y+1],x,y+1));
  76.                     }
  77.                 }
  78.         }
  79.         last=curr;
  80.     }
  81.     //cout<<get<0>(last[0])<<"X: "<<get<1>(last[0])<<" Y: "<<get<2>(last[0]);
  82.     fout<<get<0>(last[0]);
  83.     return 0;
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement