Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- struct Point
- {
- Point(int ax, int ay) : x(ax), y(ay)
- {
- }
- int x;
- int y;
- };
- int faire_exploser(Point const& MapSize, int power, Point const& bomb, std::vector<std::vector<short> >& mat, Point const& player)
- {
- for(int y = std::max(0, bomb.y - power) ; y < std::min(MapSize.y, bomb.y + power) ; ++y)
- {
- if(player.y == y && player.x == bomb.x)
- return 1;
- if(mat[y][bomb.x] > 0 && y != bomb.y)
- {
- Point newBombPos(bomb.x, y);
- if(faire_exploser(MapSize, mat[y][bomb.x], newBombPos, mat, player))
- return 1;
- }
- }
- for(int x = std::max(0, bomb.x - power) ; x < std::min(MapSize.x, bomb.x + power) ; ++x)
- {
- if(player.y == bomb.y && player.x == x)
- return 1;
- if(mat[bomb.y][x] > 0 && x != bomb.x)
- {
- Point newBombPos(x, bomb.y);
- if(faire_exploser(MapSize, mat[bomb.y][x], newBombPos, mat, player))
- return 1;
- }
- }
- return 0;
- }
- int armageddon(Point const& MapSize, Point const& player, Point const& bomb, std::vector<std::vector<short> >& mat)
- {
- int _Ret = faire_exploser(MapSize, mat[bomb.x][bomb.y], bomb, mat, player);
- return _Ret;
- }
- int main()
- {
- int n;
- int m;
- Point PlayerPos(0, 0), BombPos(0, 0);
- std::vector<std::vector<short> > mat;
- std::cin >> n;
- std::cin.ignore();
- std::cin >> m;
- std::cin.ignore();
- std::cin >> PlayerPos.x >> PlayerPos.y;
- std::cin.ignore();
- std::cin >> BombPos.x >> BombPos.y ;
- std::cin.ignore();
- mat.resize(n);
- for(int _l = 0; _l < n; ++_l)
- mat[_l].resize(m);
- for(int _l = 0; _l < n; ++_l)
- for(int _c = 0; _c < m; ++_c)
- std::cin >> mat[_l][_c];
- Point MapSize(n, m);
- int _ret = armageddon(MapSize, PlayerPos, BombPos, mat);
- std::cout << _ret << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment