move between numbers

题目:

https://codeforces.com/group/d3FEQxSUNi/contest/335515/problem/I

不要忘了-1

#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
int n,s,e;
string a[253];
int d[253],v[253];
queue<int> q;
int jud(int te,int i)
{
    int wte[10]={0},wi[10]={0};
    for(int j=0;j<20;j++)
    {
        wte[a[te][j]-0]++;
        wi[a[i][j]-0]++;
    }
    int res=0;
    for(int j=0;j<10;j++)
    {
        res+=min(wte[j],wi[j]);
    }
    return res==17;
}
void bfs(int s)
{ while(!q.empty())
   q.pop();
    d[s]=0;
    v[s]=1;
    q.push(s);
    while(!q.empty())
    {
        int te=q.front();
        q.pop();
        for(int i=1;i<=n;i++)
        {
            if(!v[i]&&jud(te,i))
            {
                v[i]=1;
                d[i]=d[te]+1;
                q.push(i);

                if(i==e)
                    return;
            }
        }
    }
    if(v[e])
        return;
}
int main()
{
    int t;
    cin>>t;
    while(t--)
     { memset(v,0,sizeof(v));
         cin>>n>>s>>e;
         getchar();
         for(int i=1;i<=n;i++)
            cin>>a[i];
        bfs(s);
        if(v[e]==0)
            printf("-1\n");
        else
        printf("%d\n",d[e]);

     }
}

 

move between numbers

上一篇:gsoap生成框架报错:GSOAP VERSION xxxxxx MISMATCH IN GENERATED CODE VERSUS LIBRARY CODE: PLEASE REINSTALL PACKAGE


下一篇:虚拟机四种引用类型和对象的生命周期