zoukankan      html  css  js  c++  java
  • hdu-1181(bfs)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1181

    思路:bfs,就是每次找到匹配麻烦一点,注意如果结尾和开头相同,就不算。

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<vector>
    #include<queue>
    using namespace std;
    int vis[120],st,ed;
    char str[120];
    struct Node{
        int x,y;
    };
    vector <Node> vc;
    void bfs()
    {
        int i,j;
        memset(vis,0,sizeof(vis));
        queue <Node> q;
        for(i=0;i<vc.size();i++)
        if(vc[i].x==st)
        {
            vis[i]=1;
            q.push(vc[i]);
        }
        while(!q.empty())
        {
            Node tmp=q.front();
            q.pop();
            if(tmp.y==ed)
            {
                printf("Yes.
    ");
                return ;
            }
            for(i=0;i<vc.size();i++)
            if(vc[i].x==tmp.x&&vc[i].y==tmp.y)
            vis[i]=1;
            for(i=0;i<vc.size();i++)
            {
                if(!vis[i]&&tmp.y==vc[i].x)
                {
                    q.push(vc[i]);
                }
            }
        }
        printf("No.
    ");
    }
    int main(void)
    {
        st='b'-'a';
        ed='m'-'a';
        while(~scanf("%s",str))
        {
            if(str[0]=='0')
            {
                bfs();
                vc.clear();
            }
            Node tmp;
            tmp.x=str[0]-'a';
            tmp.y=str[strlen(str)-1]-'a';
            if(tmp.x==tmp.y) continue;
            vc.push_back(tmp);
        }
        return 0;
    }
  • 相关阅读:
    nginx日志、变量
    http相关
    nginx.conf文件的使用
    NA交换①
    第一章 何为网络
    第二章 以太网
    SATA、SCSI、SAS
    第十章 安全
    附录A 思科互联网络操作系统(IOS)
    标准ACL、扩展ACL和命名ACL的配置详解
  • 原文地址:https://www.cnblogs.com/2018zxy/p/9940446.html
Copyright © 2011-2022 走看看