zoukankan      html  css  js  c++  java
  • HDU 1226 超级密码 (搜素)

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1226


    题意简单,本来是一道很简单的搜素题目。

    但是有两个bug:

    1、M个整数可能有重复的。

    2、N可能为0。

    你说这两个bug有意思么,特别是第二个,真没意思。


    AC代码::

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <string>
    #include <cstdlib>
    #include <cmath>
    #include <vector>
    #include <list>
    #include <deque>
    #include <queue>
    #include <iterator>
    #include <stack>
    #include <map>
    #include <set>
    #include <algorithm>
    #include <cctype>
    #include <ctime>
    #pragma comment(linker, "/STACK:16777216")
    using namespace std;
    
    typedef __int64 LL;
    const int N=5005;
    const int M=555555;
    const int INF=0x3f3f3f3f;
    const double PI=acos(-1.0);
    const double eps=1e-7;
    
    int n,c,m;
    int h[27];
    bool vis[N];
    struct xh
    {
        int left,step;
        string s;
    }w,e;
    
    int char_int(char k)
    {
        if(k<='9')
            return k-'0';
        return k-'A'+10;
    }
    
    char int_char(int k)
    {
        if(k<=9)
            return k+'0';
        return k-10+'A';
    }
    
    void BFS()
    {
        int i,t;
        memset(vis,0,sizeof(vis));
        queue<xh>q;
        for(i=0;i<m;i++)
        {
            if(h[i]==0)    continue;
            w.left=h[i]%n;
            w.s="";
            w.s+=int_char(h[i]);
            w.step=1;
            if(w.left==0)
            {
                cout<<w.s<<endl;
                return ;
            }
            if(!vis[w.left])
            {
                q.push(w);
                vis[w.left]=1;
            }
        }
        while(!q.empty())
        {
            e=q.front();
            q.pop();
            if(e.step>=500)
                continue;
            for(i=0;i<m;i++)
            {
                w=e;
                w.left=(w.left*c+h[i])%n;
                if(vis[w.left]) continue;
                vis[w.left]=1;
                w.step++;
                w.s+=int_char(h[i]);
                if(w.left==0)
                {
                    cout<<w.s<<endl;
                    return ;
                }
                q.push(w);
            }
        }
        puts("give me the bomb please");
    }
    
    int main()
    {
        int T;
        cin>>T;
        while(T--)
        {
            scanf("%d%d",&n,&c);
            scanf("%d",&m);
            int tt[20];
            memset(tt,0,sizeof(tt));
            for(int i=0;i<m;i++)
            {
                char k;
                cin>>k;
                int p=char_int(k);
                tt[p]=1;
            }
            m=0;
            for(int i=0;i<16;i++)
                if(tt[i])
                    h[m++]=i;
            if(n==0)
            {
                if(h[0]==0)
                    puts("0");
                else
                    puts("give me the bomb please");
                continue;
            }
            BFS();
        }
        return 0;
    }
    


  • 相关阅读:
    UVALive 5983 MAGRID DP
    2015暑假训练(UVALive 5983
    poj 1426 Find The Multiple (BFS)
    poj 3126 Prime Path (BFS)
    poj 2251 Dungeon Master 3维bfs(水水)
    poj 3278 catch that cow BFS(基础水)
    poj3083 Children of the Candy Corn BFS&&DFS
    BZOJ1878: [SDOI2009]HH的项链 (离线查询+树状数组)
    洛谷P3178 [HAOI2015]树上操作(dfs序+线段树)
    洛谷P3065 [USACO12DEC]第一!First!(Trie树+拓扑排序)
  • 原文地址:https://www.cnblogs.com/riskyer/p/3283603.html
Copyright © 2011-2022 走看看