Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
【求助】给点测试数据吧……用了题目的数据和自己的数据都正确……#include <iostream> #include <string> using namespace std; int index =0;//sign the number of the pools string m[102]; char clour[101][101]; void DFSVist(int i, int j) { clour[i][j] = 1; for (int n =j-1;n<=j+1;++n) { for (int k = i-1;k<=i+1;++k) { if(m[k][n]=='W' && !clour[k][n]) DFSVist(k,n); } } clour[i][j] = 2; } int main() { int N,M; cin>>N>>M; for(int i= 0;i<102;++i) m[i] = string(100,'.'); string temp; for(int i = 1;i<=N;++i){ m[i] = "."; cin>>temp; m[i]+=temp; m[i] += "."; } for (int i = 1;i<=N;++i) { for (int j =1;j<=M;++j) { clour[i][j] = 0; } } for (int i = 1;i<N;++i) { for (int j =1;j<M;++j) { if(m[i][j] == 'W' && !clour[i][j]){ DFSVist(i,j); ++index; } } } cout<<index<<endl; return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator