Created
December 28, 2014 05:16
-
-
Save ik11235/84990e223be7372b25a2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TheKingsArmyDiv2 { | |
public: | |
int getNumber(vector<string> state) { | |
int ans=2; | |
int dx[]={1,-1,0,0}; | |
int dy[]={0,0,1,-1}; | |
for (int i=0; i < state.size(); i++) { | |
for (int j=0; j < state[i].size(); j++) { | |
if(state[i][j]=='H') | |
{ | |
ans=min(ans,1); | |
for(int x=0;x<4;x++) | |
{ | |
if(i+dx[x]>=0&&i+dx[x]<state.size()&& | |
j+dy[x]>=0&&j+dy[x]<state[i].size()&& | |
state[i+dx[x]][j+dy[x]]=='H' | |
) | |
ans=0; | |
} | |
} | |
} | |
} | |
return ans; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment