根据题意的 Runaround 规则去找比当前数大的最近的一个 Runaround数字

模拟题~

Source code:

/*
ID: wushuai2
PROG: runround
LANG: C++
*/
//#pragma comment(linker, "/STACK:16777216") //for c++ Compiler
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <cstring>
#include <cmath>
#include <stack>
#include <string>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <vector>
#include <algorithm>
#define Max(a,b) (((a) > (b)) ? (a) : (b))
#define Min(a,b) (((a) < (b)) ? (a) : (b))
#define Abs(x) (((x) > 0) ? (x) : (-(x)))
#define MOD 1000000007
#define pi acos(-1.0) using namespace std; typedef long long ll ;
typedef unsigned long long ull ;
typedef unsigned int uint ;
typedef unsigned char uchar ; template<class T> inline void checkmin(T &a,T b){if(a>b) a=b;}
template<class T> inline void checkmax(T &a,T b){if(a<b) a=b;} const double eps = 1e- ;
const int M = ;
const ll P = 10000000097ll ;
const int INF = 0x3f3f3f3f ;
const int MAX_N = ;
const int MAXSIZE = ; ll num;
ll a[]; void toStr(ll num){
int i, j, k;
memset(a, , sizeof(a));
while(num){
a[++a[]] = num % 10LL;
num /= 10LL;
}
for(i = ; i <= a[] / ; ++i){
swap(a[i], a[a[] - i + ]);
}
} void toNum(){
int i, j, k;
num = ;
ll nl = 1LL;
for(i = a[]; i >= ; --i){
num += nl * a[i];
nl *= 10LL;
}
} bool solve(){
int i, j, k, pos;
ll ans[];
ll cur = a[];
ll b[], bigg = ;
bool vis[];
memset(vis, , sizeof(vis));
memset(ans, , sizeof(ans));
for(i = ; i <= a[]; ++i){
checkmax(bigg, a[i]);
if(a[i] == ) return false;
if(ans[a[i]]) return false;
ans[a[i]] = true;
}
for(;;){
memset(b, , sizeof(b));
for(pos = ; pos <= a[]; ++pos){
if(cur == a[pos]) break;
}
for(i = pos; i <= cur + pos - ; ++i){
b[++b[]] = a[i % a[] + ];
}
/*
for(i = 1; i <= b[0]; ++i){
cout << b[i];
}
cout << endl;
*/
if(vis[b[b[]]]) return false;
else vis[b[b[]]] = true;
for(i = ; i <= bigg; ++i){
if(vis[i] != ans[i]) break;
}
if(i == bigg + ) return true;
cur = b[b[]];
}
} int main() {
ofstream fout ("runround.out");
ifstream fin ("runround.in");
int i, j, k, t, n, s, c, w, q;
fin >> num;
++num;
toStr(num);
/*
for(i = 1; i <= a[0]; ++i){
cout << a[i];
}
cout << endl;
*/
while(!solve()){
//cout << num << endl;
toNum();
++num;
toStr(num);
}
fout << num << endl; fin.close();
fout.close();
return ;
}
04-16 12:47