码迷,mamicode.com
首页 > 其他好文 > 详细

Wetlands of Florida UVA - 469

时间:2017-05-28 20:15:45      阅读:212      评论:0      收藏:0      [点我收藏+]

标签:span   提取   splay   int   方向   names   简单   put   mem   

题很简单 意思就是 给出某点坐标,看看附近有几个W,附近指的是8个方向,上、下、左、右、左上、左下、右上、右下。

就是输入格式有点麻烦。再一次体会到 sscanf 函数的 强大。

技术分享
#include <cstdio>
#include <cstring>
using namespace std;
char map[105][105],used[105][105];
int ans;
void dfs(int x, int y)
{
    if(x < 0 || y < 0 || map[x][y] == 0)
        return;
    if(used[x][y]|| map[x][y] != W)
        return;
    used[x][y] = 1;
    ans ++;
    int i, j;
    for(i = -1; i <= 1; i++)
    for(j = -1; j <= 1; j++)
        dfs(x+i, y+j);
}
int main()
{
    int t, i, j;
    char str[105];
    scanf("%d ", &t);
    while(t--)
    {
        memset(map,0,sizeof(map));
        int n = 0;
        while(gets(str))
        {
            if(str[0] == \0)
                break;
            if(str[0] != W && str[0] != L)
            {
                sscanf(str, "%d %d", &i, &j); // 从当前字符串提取两个数字分别为i,j;
                memset(used, 0, sizeof(used));
                ans = 0;
                dfs(i-1, j-1);
                printf("%d\n", ans);
            }
            else
            {
                sscanf(str, "%s", map[n++]);
            }
        }
        if(t) printf("\n");  // <==>  puts("");
    }
    return 0;
}
View Code

 

Wetlands of Florida UVA - 469

标签:span   提取   splay   int   方向   names   简单   put   mem   

原文地址:http://www.cnblogs.com/wangshuazi/p/6916413.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!