hdu 1181

#pragma warning ( disable: 4786 )
#include<iostream>
#include<vector>
#include<string>
using namespace std;
vector<string> svec;
bool find,havem1,havem2;
int s[10000];

void dfs( int i )
{
    if( svec[i][svec[i].size()-1] == 'm' )
    {
        find=true;
        return ;
    }
    for( int j=0;j<svec.size();j++ )
    {
        if( svec[i][svec[i].size()-1] == svec[j][0] && s[j]==0 )
        {
            s[j]=1;
            dfs( j );
        }
    }
   
}


int main()
{
    string str;
    bool cntb=false,cntm=false;
    find=false;
    havem1=false;
    havem2=false;
    while( cin>>str )
    {
        memset( s,0,sizeof(s) );
        if( str.size()==1 && str[0] != '0' )
            continue;
        if( str[0]=='0'  )
        {
            if( !(havem1 && havem2 ))
            {
                printf("No./n");
                find=false;
                havem1=false;
                havem2=false;
                svec.clear();
                memset( s,0,sizeof(s) );
                continue;
            }
            for( int i=0;i<svec.size();i++ )
            {
                if( find == true )
                    break;
                if( svec[i][0]=='b' )
                    dfs( i );
            }
            if( find == true  )
                printf("Yes./n");
            else
                printf("No./n");
            find=false;
            havem1=false;
            havem2=false;
            svec.clear();
            memset( s,0,sizeof(s) );
        }
        else
        {
            svec.push_back(str);
            if(str[str.size()-1]=='m')
                havem2=true;
            if( str[0]=='m' )
                havem1=true;
        }


    }


    return 0;
}

 

悲剧啊,原来Runtime Error(STACK_OVERFLOW)的原因是递归过多。。还好汇编学的好。。分析出来了。。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值