p1467 Runaround Numbers

直接搜就行。

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cstring>
#include <map>
#include <queue>
#include <set>
#include <cassert>
#include <stack>
#define mkp make_pair
using namespace std;
const double EPS=1e-8;
typedef long long lon;
const lon SZ=30,INF=0x7FFFFFFF;

bool chk(int x)
{
    set<int> st;
    for(;x;)
    {
        if(st.find(x%10)!=st.end())return 0;
        else st.insert(x%10);
        if(x%10==0)return 0;
        x/=10;
    }
    return 1;
}

int getdgt(int x)
{
    int res=0;
    for(;x;)
    {
        x/=10;
        ++res;
    }
    return res;
}

bool work(int x)
{
    int dgt=getdgt(x);
    int pos=dgt-1,src=pos;
    set<int> st;
    for(;;)
    {
        if(st.find(pos)!=st.end())
        {
            if(pos==src&&st.size()==dgt)return 1;
            else return 0;
        }
        st.insert(pos);
        //if(st.size()==dgt)break;
        int delta=x/(int)(pow(10,pos)+0.5)%10;
        pos=((pos-delta)%dgt+dgt)%dgt;
    }
    return 1;
}

int main()
{
    std::ios::sync_with_stdio(0);
    //freopen("d:\\1.txt","r",stdin);
    lon casenum;
    //cin>>casenum;
    //for(lon time=1;time<=casenum;++time)
    {
        int n;
        cin>>n;
        for(int i=n+1;;++i)
        {
            if(chk(i))
            {
                if(work(i))
                {
                    cout<<i<<endl;
                    break;
                }
            }
        }
    }
    return 0;
}

 

posted @ 2018-10-20 21:34  degvx  阅读(171)  评论(0编辑  收藏  举报