We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
voidexplode(vector<string>*grid,vector<string>*result){for(introw=0;row<(*grid).size();row++){for(intcol=0;col<(*grid)[0].size();col++){if((*grid)[row][col]=='O'){(*result)[row][col]='.';if(col-1>=0)(*result)[row][col-1]='.';if(row-1>=0)(*result)[row-1][col]='.';if(col+1<(*result)[0].size())(*result)[row][col+1]='.';if(row+1<(*result).size())(*result)[row+1][col]='.';}}}}vector<string>bomberMan(intn,vector<string>grid){//These solutions are trivialif(n==1)returngrid;stringrow(grid[0].size(),'O');vector<string>result(grid.size(),row);if(n%2==0)returnresult;/*The first detonation and second detonation patterns keep repeating. The only thing I need to check is if n belongs to the arithmetic sequence with d=4 and a1=3 (first detonation) or a1=5 (second detonation).*/explode(&grid,&result);if((n-3)%4==0)returnresult;grid=result;fill(result.begin(),result.end(),row);if((n-5)%4==0){explode(&grid,&result);returnresult;}return{"*"};}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
The Bomberman Game
You are viewing a single comment's thread. Return to all comments →
C++