tobast

Untitled

May 2nd, 2012
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.74 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. struct Point
  5. {
  6.     Point(int ax, int ay) : x(ax), y(ay)
  7.     {
  8.  
  9.     }
  10.     int x;
  11.     int y;
  12. };
  13.  
  14. int faire_exploser(Point const& MapSize, int power, Point const& bomb, std::vector<std::vector<short> >& mat, Point const& player)
  15. {
  16.     for(int y = std::max(0, bomb.y - power) ; y < std::min(MapSize.y, bomb.y + power) ; ++y)
  17.     {
  18.         if(player.y == y && player.x == bomb.x)
  19.             return 1;
  20.         if(mat[y][bomb.x] > 0 && y != bomb.y)
  21.         {
  22.             Point newBombPos(bomb.x, y);
  23.             if(faire_exploser(MapSize, mat[y][bomb.x], newBombPos, mat, player))
  24.                 return 1;
  25.         }
  26.  
  27.     }
  28.     for(int x = std::max(0, bomb.x - power) ; x < std::min(MapSize.x, bomb.x + power) ; ++x)
  29.     {
  30.         if(player.y == bomb.y && player.x == x)
  31.             return 1;
  32.         if(mat[bomb.y][x] > 0 && x != bomb.x)
  33.         {
  34.             Point newBombPos(x, bomb.y);
  35.             if(faire_exploser(MapSize, mat[bomb.y][x], newBombPos, mat, player))
  36.                 return 1;
  37.         }
  38.     }
  39.     return 0;
  40. }
  41.  
  42. int armageddon(Point const& MapSize, Point const& player, Point const& bomb, std::vector<std::vector<short> >& mat)
  43. {
  44.     int _Ret = faire_exploser(MapSize, mat[bomb.x][bomb.y], bomb, mat, player);
  45.     return _Ret;
  46. }
  47.  
  48. int main()
  49. {
  50.     int n;
  51.     int m;
  52.     Point PlayerPos(0, 0), BombPos(0, 0);
  53.     std::vector<std::vector<short> > mat;
  54.  
  55.     std::cin >> n;
  56.     std::cin.ignore();
  57.     std::cin >> m;
  58.     std::cin.ignore();
  59.     std::cin >> PlayerPos.x >> PlayerPos.y;
  60.     std::cin.ignore();
  61.  
  62.     std::cin >> BombPos.x >> BombPos.y ;
  63.     std::cin.ignore();
  64.  
  65.     mat.resize(n);
  66.     for(int _l = 0; _l < n; ++_l)
  67.         mat[_l].resize(m);
  68.  
  69.     for(int _l = 0; _l < n; ++_l)
  70.         for(int _c = 0; _c < m; ++_c)
  71.             std::cin >> mat[_l][_c];
  72.  
  73.     Point MapSize(n, m);
  74.  
  75.     int _ret = armageddon(MapSize, PlayerPos, BombPos, mat);
  76.     std::cout << _ret << std::endl;
  77.  
  78.     return 0;
  79.  
  80. }
Advertisement
Add Comment
Please, Sign In to add comment