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:这个题目是有是有问题!指明了说每个deposit最多不超过100,我加上这个条件就错,去了反而对了,代码如下,哪位大牛能解释一下?In Reply To:这个题目是有是有问题!指明了说每个deposit最多不超过100,我加上这个条件就错,去了反而对了,代码如下,哪位大牛能解释一下? Posted by:fanliqian at 2009-12-16 16:09:34 > #include<iostream> > using namespace std; > > bool map[110][110], visit[110][110]; > int n, m, ans, dir[8][2] = { {0,1}, {1, 0}, {-1, 0}, {0, -1}, {1, 1}, {-1, -1}, {-1, 1}, {1, -1}}; > > void dfs(int x, int y, int &num) > { > int i,tx, ty; > > for(i = 0; i < 8; i++) { > tx = dir[i][0] + x; > ty = dir[i][1] + y; > if(tx >= 0 && tx < m && ty >= 0 && ty < n && !visit[tx][ty]) { > visit[tx][ty] = 1; > if(map[tx][ty] ) dfs(tx, ty, ++num); > } > } > } > > > int main() > { > int i, j, k; > char ch[110]; > while(scanf("%d%d", &m, &n) != EOF) { > if(m == 0) break; > for(i = 0; i < m; i++) { > scanf("%s", ch); > for(j = 0; j < n; j++) { > map[i][j] = (ch[j] == '@'); > } > } > for(i = 0; i < m; i++) { > for(j = 0; j < n; j++) { > if(!visit[i][j] && map[i][j]) { > k = 1; > dfs(i, j, k); > //ans += (99+k)/100; > ans++; > } > visit[i][j] = 1; > } > } > printf("%d\n" ,ans); > ans = 0; > memset(visit, 0, sizeof(visit)); > memset(map, 0, sizeof(map)); > } > return 0; > } > > > 将上面ans++换成(99+k)/100就不对,如果一个联通中@的的个数大于100到底是用几个deposit? 题目这句话只是告诉你ans不会多于100 而不是告诉你当ans多于100时该怎么办 Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator