TCHS SRM 46 Level one - 250 pt - Pawns editorial: http://community.topcoder.com/tc?module=Static&d1=hs&d2=match_editorials&d3=hs_srm46
TCHS SRM 46 Level one - 250 pt - Pawns solution:
#include <iostream> #include <vector> class Pawns{ public: int pawnsAttack(std::vector <std::string> p) { int a[8][8]={0}, b[8][8]={0}, cnt=0; for(int i=0; i<p.size(); i++) a[8-(p[i][1]-'0')][p[i][0]-'a']++; for(int i=1; i<8; i++) for(int j=0; j<8; j++) if(a[i][j]) { if(j==0) { if(!a[i-1][j+1] && !b[i-1][j+1]) cnt++, b[i-1][j+1]++; } else if(j==7) { if(!a[i-1][j-1] && !b[i-1][j-1]) cnt++, b[i-1][j-1]++; } else { if(!a[i-1][j-1] && !b[i-1][j-1]) cnt++, b[i-1][j-1]++; if(!a[i-1][j+1] && !b[i-1][j+1]) cnt++, b[i-1][j+1]++; } } return cnt; } };
No comments:
Post a Comment