usaco training-Runaround Numbers
2011-06-02 17:56
232 查看
//usaco training-Runaround Numbers /* * 类型:枚举 * 思路:先判断是否满足不含数字0 和 数字无重复这一条件 * 后进行其他证明 * 将整数转化成数组的形式以方便进行数位操作 * 执行len(位数)次循环操作并作出相应的判断 */ /* Compiling... Compile: OK Executing... Test 1: TEST OK [0.000 secs, 3028 KB] Test 2: TEST OK [0.000 secs, 3028 KB] Test 3: TEST OK [0.000 secs, 3028 KB] Test 4: TEST OK [0.000 secs, 3028 KB] Test 5: TEST OK [0.081 secs, 3028 KB] Test 6: TEST OK [0.027 secs, 3028 KB] Test 7: TEST OK [0.162 secs, 3028 KB] All tests OK. YOUR PROGRAM ('runround') WORKED FIRST TIME! That's fantastic -- and a rare thing. Please accept these special automated congratulations. */ #include <iostream> #include <algorithm> #include <cstring> #include <fstream> using namespace std; unsigned long long N; int sign[10],res[50]; bool is_ligal(unsigned long long x); bool is_runround(unsigned long long x); int main(void) { unsigned long long i; ifstream fin("runround.in"); ofstream fout("runround.out"); for(fin>>N,i=N+1; ; ++i){ if(is_ligal(i) && is_runround(i)) break; } fout<<i<<endl; return 0; } bool is_ligal(unsigned long long x) { memset(sign,0,sizeof(sign)); while(x){ if(!(x%10) || sign[x%10]) return false; x/=10; } return true; } bool is_runround(unsigned long long x) { int i,step,len=0,k=0; while(x){ res[len++]=x%10; x/=10; } reverse(res,res+len); memset(sign,0,sizeof(sign)); sign[res[0]]=1,i=0; while(k!=len){ step=res[i]%len; i=i+step; if(i>=len) i=(i+len)%len; if(!sign[res[i]]) sign[res[i]]=1; else if((k==len-1 && i!=0) || k!=len-1) return false; k++; } return true; }
相关文章推荐
- USACO2.2.3 Runaround Numbers (runround)
- 【USACO 2.2】Runaround Numbers
- USACO 2.2 Runaround Numbers
- USACO-Runaround Numbers(枚举)
- USACO-Section2.2 Runaround Numbers [其他][模拟]
- usaco2.23Runaround Numbers
- USACO 2.2.3 Runaround Numbers
- usaco Runaround Numbers
- USACO - 2.2 Runaround Numbers(枚举)
- USACO-Runaround Numbers
- USACO 2.2.3 Runaround Numbers 循环数
- [USACO 2.2.3] Runaround Numbers
- USACO2.2.3 Runaround Numbers (runround)
- USACO - Chapter2 Section 2.2 - Runaround Numbers
- USACO 2.2 Runaround Numbers
- USACO :Runaround Numbers 解题报告
- Runaround Numbers_usaco2.2.3_预处理+二分
- USACO:Runaround Numbers
- USACO-Section2.2 Runaround Numbers
- [USACO2.2]循环数 Runaround Numbers