HDU2699+Easy
生活随笔
收集整理的這篇文章主要介紹了
HDU2699+Easy
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
簡(jiǎn)單題。
?
/**/ #include<stdio.h> #include<string.h> #include<stdlib.h> #include<algorithm> #include<iostream> #include<queue> #include<map> #include<stack> #include<set> #include<math.h> using namespace std; typedef long long int64; //typedef __int64 int64; typedef pair<int64,int64> PII; #define MP(a,b) make_pair((a),(b)) const int maxn = 18; const int inf = 0x7fffffff; const double pi=acos(-1.0); const double eps = 1e-8; char mat[ maxn ][ maxn ]; bool flag; const int dx[]={1,-1,0,0,-1,-1,1,1}; const int dy[]={0,0,1,-1,-1,1,-1,1};bool in( int x,int y ){if( x>=0&&x<15&&y>=0&&y<15 )return true;elsereturn false; }bool Judge( int x,int y,char xx ){for( int i=0;i<8;i++ ){int tx = x+dx[i];int ty = y+dy[i];if( in(tx,ty)==true&&mat[tx][ty]==xx )return true;}return false; }int bfs( int x,int y,char xx ){int tx = x+1;int ty = y;int cnt = 0;while( tx<15 ){if( mat[tx][ty]==xx ){cnt++;tx++;if( cnt>=4 ) break;}else break;}tx = x-1;while( tx>=0 ){if( mat[tx][ty]==xx ){cnt++;tx--;if( cnt>=4 ) break;}else break;}if( cnt>=4 ) return 5;//row to "5"tx = x;ty = y+1;cnt = 0;while( ty<15 ){if( mat[tx][ty]==xx ){cnt++;ty++;if( cnt>=4 ) break;}else break;}ty = y-1;while( ty>=0 ){if( mat[tx][ty]==xx ){cnt++;ty--;if( cnt>=4 ) break;}else break;}if( cnt>=4 ) return 5;// col to "5"tx = x+1;ty = y+1;cnt = 0;while( tx<15&&ty<15 ){if( mat[tx][ty]==xx ){cnt++;tx++;ty++;if( cnt>=4 ) break;}else break;}tx = x-1;ty = y-1;while( tx>=0&&ty>=0 ){if( mat[tx][ty]==xx ){cnt++;tx--;ty--;if( cnt>=4 ) break;}else break;}if( cnt>=4 ) return 5;//right up to "5"tx = x-1;ty = y+1;cnt = 0;while( tx>=0&&ty<15 ){if( mat[tx][ty]==xx ){cnt++;tx--;ty++;if( cnt>=4 ) break;}else break;}tx = x+1;ty = y-1;while( tx<15&&ty>=0 ){if( mat[tx][ty]==xx ){cnt++;tx++;ty--;if( cnt>=4 ) break;}else break;}if( cnt>=4 ) return 5;//left up to "5"return -1; }int main(){int T;scanf("%d",&T);while( T-- ){int cnt1 = 0;int cnt2 = 0;for( int i=0;i<15;i++ ){scanf("%s",mat[i]);for( int j=0;j<15;j++ ){if( mat[i][j]=='W' ) cnt1++;if( mat[i][j]=='B' ) cnt2++;}}char xx ;if( cnt1==cnt2 ) xx = 'B';else xx = 'W';flag = false;for( int i=0;i<15;i++ ){for( int j=0;j<15;j++ ){if( mat[i][j]=='.'&&Judge( i,j,xx )==true ){//i,j周圍有 xxif( bfs( i,j,xx )>=5 ){flag = true;break;}}}if( flag==true ) break;}if( flag ) puts("YES");else puts("NO");}return 0; }?
總結(jié)
以上是生活随笔為你收集整理的HDU2699+Easy的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Q5.2
- 下一篇: Linux 高可用(HA)集群之Pace