标签:
没什么好说的强行搜索。具体细节看代码。
/*
ID: awsd1231
PROG: runround
LANG: C++
*/
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
using namespace std;
unsigned long M;
bool check(unsigned long x) {
char buf[10];
sprintf(buf, "%u", x);
int ans[10][2] = {0};
int len = strlen(buf);
for (int i = 0; i != len - 1; ++i) {
for (int j = i + 1; j != len; ++j) {
if (buf[i] == buf[j] || !buf[j]) {
return false;
}
}
}
for (int i = 0; i != len; ++i) {
ans[i][0] = buf[i] - ‘0‘;
}
int idx = 0;
if (ans[idx][0] >= len) {
idx = ans[idx][0] % len;
}
else idx = ans[idx][0];
for (int i = 0; i != len; ++i) {
if (ans[idx][1]) return false;
ans[idx][1] = 1;
if (idx + ans[idx][0] >= len) {
idx = (idx + ans[idx][0]) % len;
}
else
idx += ans[idx][0];
}
return true;
}
int main () {
freopen("runround.in", "r", stdin);
freopen("runround.out", "w", stdout);
cin >> M;
for (unsigned long i = M + 1; ; ++i) {
if (i % 10 && check(i)) {
cout << i << endl;
break;
}
}
return 0;
}
标签:
原文地址:http://www.cnblogs.com/liangyongrui/p/4558154.html