题意:
求比给出的M大的循环数, 循环数,从位置0开始数arr[0]个数,然后再从位置i数arr[i]个数,最后回到起点
解法:
简单模拟
/* ID: lsswxr1 PROG: runround LANG: C++ */ #include <iostream> #include <vector> #include <map> #include <list> #include <set> #include <deque> #include <stack> #include <queue> #include <algorithm> #include <cmath> #include <cctype> #include <cstdio> #include <iomanip> #include <cmath> #include <cstdio> #include <string> #include <cstring> #include <fstream> using namespace std; #define USACO #ifdef USACO #define cin fin #define cout fout #endif ////////////////////////////////////////////////////////////////////////// ///宏定义 const int INF = 1000000000; const int MAXN = 40001; const int maxn = MAXN; ///全局变量 和 函数 long long N; int nums[30]; bool vis[30]; bool hasNum[10]; bool isok(int cur) { memset(hasNum, false, sizeof(hasNum)); int cnt = 0; int temp[30]; int divNum = 10; int Number = cur; while (Number != 0) { int saveNum = Number % 10; if (saveNum == 0 || hasNum[saveNum] == true) return false; hasNum[saveNum] = true; temp[cnt++] = saveNum; // divNum *= 10; Number /= divNum; } int j = 0; for (int i = cnt - 1; i >= 0; i--) { nums[j++] = temp[i]; } memset(vis, false, sizeof(vis)); int counter = 0; int startNum = nums[0]; int startPos = 0; vis[0] = true; counter++; while (counter < cnt) { startPos = (startPos + startNum) % cnt; if (vis[startPos]) { return false; } else { vis[startPos] = true; startNum = nums[startPos]; counter++; } } int results = (startPos + startNum) % cnt; if (results == 0) return true; return false; } int main() { #ifdef USACO ofstream fout ("runround.out"); ifstream fin ("runround.in"); #endif while (cin >> N) { int M = N + 1; while (1) { if (isok(M)) { cout << M << endl; break; } M++; } } ///结束 return 0; }