SDUT 2721 Cash Cow BFS+坑爹输入

以前已经做过一次这样的题,第二次做还是没能一A 。。。。

一直卡在输入上,学长说把scanf() 换成 cin ,然后果断A掉了。

以此为戒吧,以后碰到类似的输入,记得用cin........Orz

#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <cmath>
#include <algorithm>
#include <string>
#include <set>
#include <stack>

#define LL long long
#define EPS (1e-8)
#define Left true
#define Right false

using namespace std;

char sta[13][11];

bool mark[13][11];

struct N
{
    int x,y;
};

void del()
{
    int i,j,k;
    for(i = 1;i <= 10; ++i)
    {
        for(j = 1;j <= 12; ++j)
        {
            if(mark[j][i] == true)
            {
                sta[j][i] = '1';
            }
        }
        for(j = 1;j <= 12; ++j)
        {
            for(k = 1;k < 12; ++k)
            {
                if(sta[k][i] == '1')
                {
                    sta[k][i] = sta[k+1][i];
                    sta[k+1][i] = '1';
                }
            }
        }
    }

    for(k = 1;k <= 10; ++k)
    {
        for(i = 1;i <= 9; ++i)
        {
            for(j = 1;j <= 12 && sta[j][i] == '1'; ++j)
                ;
            if(j == 13)
            {
                for(j = 1;j <= 12; ++j)
                {
                    sta[j][i] = sta[j][i+1];
                    sta[j][i+1] = '1';
                }
            }
        }
    }
}

int jx[] = { 0,-1, 0, 1};
int jy[] = { 1, 0,-1, 0};

int bfs(int x,int y)
{
    if(sta[x][y] == '1')
        return 0;
    int ans = 1;

    queue<N> q;
    N st,ft;

    st.x = x,st.y = y;
    q.push(st);
    mark[st.x][st.y] = true;

    while(q.empty() == false)
    {
        ft = q.front();
        q.pop();

        for(int i = 0;i < 4; ++i)
        {
            st = ft;

            st.x += jx[i];
            st.y += jy[i];

            if(1 <= st.x && st.x <= 12 && 1 <= st.y && st.y <= 10 && sta[st.x][st.y] == sta[ft.x][ft.y] && mark[st.x][st.y] == false)
            {
                q.push(st);
                mark[st.x][st.y] = true;
                ans++;
            }
        }
    }
    if(ans <= 2)
    {
        memset(mark,false,sizeof(mark));
        ans = 0;
    }
    return ans;
}

int main()
{
    int n;
    int x,y;
    char c;
    int i,j;
    int sum;

    while(scanf("%d%*c",&n) && n)
    {
        sum = 120;
        for(i = 12;i >= 1; --i)
        {
            for(j = 1;j <= 10; ++j)
            {
                cin>>sta[i][j];
            }
        }

        while(n--)
        {
            cin>>c>>x;
            
            y = c-'a'+1;
            memset(mark,false,sizeof(mark));
            sum -= bfs(x,y);
            del();
        }
        cout<<sum<<endl;
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值