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 |
Re: MAX大点就可以AC,题目说是小于20.。真晕In Reply To: MAX大点就可以AC,题目说是小于20.。真晕 Posted by:jasonnk at 2008-06-24 03:30:15 > #include <iostream> > using namespace std; > > const int MAX=101; > > int map[MAX][MAX]; > int couter; > > void getnum(int i,int j){ > map[i][j]=0; > couter++; > if(map[i-1][j]==1){map[i-1][j]=0;getnum(i-1,j);} > if(map[i+1][j]==1){map[i+1][j]=0;getnum(i+1,j);} > if(map[i][j-1]==1){map[i][j-1]=0;getnum(i,j-1);} > if(map[i][j+1]==1){map[i][j+1]=0;getnum(i,j+1);} > return; > } > > int main(){ > int w,h; > int x,y; > char t; > > while((cin>>w>>h)&&w&&h){ > for(int i=0;i<MAX;i++){for(int j=0;j<MAX;j++){map[i][j] = 0;}} > couter = 0; > x=y=0; > for(int i=0;i<h;i++){ > for(int j=0;j<w;j++){ > cin >> t; > if(t=='.'){map[i][j] = 1;} > if(t=='#'){map[i][j] = 0;} > if(t=='@'){map[i][j] = 1;y=i;x=j;} > } > } > getnum(y,x); > cout << couter << endl; > } > > > return 1; > } 我把你的提交不能ac 说是wrong answer 但是我认为你的算法是正确的 for(int i=0;i<MAX;i++){for(int j=0;j<MAX;j++){map[i][j] = 0;}} 这个没必要要吧? Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator