Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Author: 曹北健(37509)
- Result: AC Submission_id: 4439921
- Created at: Sun May 15 2022 15:15:51 GMT+0800 (China Standard Time)
- Problem: 5779 Time: 6 Memory: 1784
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <ctype.h>
- #include <math.h>
- #include <string.h>
- #include <assert.h>
- #pragma warning(disable:4996)
- int n,m;
- char map[114][514] = {0};
- void dfs(int x,int y){
- if(map[x][y] == '*')return;
- else{
- map[x][y] = '*';
- int dx,dy;
- for(dx = -1;dx <= 1;dx++){
- for(dy = -1;dy <= 1;dy++){
- if(x + dx >= 0 && x + dx < n && y + dy >= 0 && y + dy < m){
- dfs(x + dx,y + dy);
- }
- }
- }
- }
- }
- int main(){
- int i,j,ans = 0;
- scanf("%d%d",&n,&m);
- for(i = 0;i < n;i++){
- scanf("%s",map[i]);
- }
- for(i = 0;i < n;i++){
- for(j = 0;j < m;j++){
- if(map[i][j] == 'W'){
- dfs(i,j);ans++;
- }
- }
- }
- printf("%d\n",ans);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment