Advertisement
Guest User

Untitled

a guest
Feb 6th, 2016
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. #include <vector>
  2. #include <list>
  3. #include <map>
  4. #include <set>
  5. #include <queue>
  6. #include <deque>
  7. #include <stdio.h>
  8. #include <string.h>
  9. #include <stack>
  10. #include <bitset>
  11. #include <algorithm>
  12. #include <functional>
  13. #include <numeric>
  14. #include <utility>
  15. #include <sstream>
  16. #include <iostream>
  17. #include <iomanip>
  18. #include <cstdio>
  19. #include <cmath>
  20. #include <cstdlib>
  21. #include <ctime>
  22.  
  23. using namespace std;
  24.  
  25. string way;
  26. bool ok;
  27. const int N = 80;
  28. char dp[N][N][N][N];
  29. int l;
  30. class ExplodingRobots {
  31. public:
  32. int dfs(int x1,int y1,int x2,int y2){
  33. if (x1 == x2 && y1 == y2){
  34. ok = 1;
  35. return dp[x1][y1][x2][y2] = 1;
  36. }
  37. if (dp[x1][y1][x2][y2] == -1){
  38. if (l < way.size()) {
  39. int dx = 0,dy = 0;
  40. if (way[l] == 'U'){
  41. dy = 1;
  42. }
  43. if (way[l] == 'D'){
  44. dy = -1;
  45. }
  46. if (way[l] == 'R'){
  47. dx = 1;
  48. }
  49. if (way[l] == 'L'){
  50. dx = -1;
  51. }
  52. l++;
  53. dfs(x1 + dx,y1 + dy, x2, y2);
  54. dfs(x1,y1, x2 + dx, y2 + dy);
  55. dfs(x1 + dx,y1 + dy, x2 + dx, y2 + dy);
  56. l--;
  57. }
  58. return dp[x1][y1][x2][y2] = 1;
  59. }
  60. else return dp[x1][y1][x2][y2];
  61. }
  62. string canExplode(int x1, int y1, int x2, int y2, string instructions) {
  63. way = instructions;
  64. memset(dp,-1,sizeof dp);
  65. dfs(x1,y1,x2,y2);
  66. if (ok){
  67. return "Explosion";
  68. }
  69. else
  70. return "Safe";
  71. }
  72. };
  73.  
  74.  
  75. <%:testing-code%>
  76. //Powered by KawigiEdit 2.1.8 (beta) modified by pivanof!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement