USACO 2.2.3 Runaround Numbers

来源:互联网 发布:矩阵的谱范数怎么求 编辑:程序博客网 时间:2024/05/19 04:28

暴力枚举+模拟验证,注意判断条件

#include <iostream>#include <fstream>#include <string>#include <map>#include <string.h>#define LL long long//#define LOCALusing namespace std;#ifdef LOCALofstream fout ("out.txt");ifstream fin ("in.txt");#elseofstream fout ("runround.out");ifstream fin ("runround.in");#endifint visited[10];bool check(int num2){int pos[10];int cnt = 0;int temp = num2;while(temp){pos[cnt++] = temp%10;if(temp%10==0)            return 0;temp /= 10;}int cnt2 = 0;int now = cnt-1;while(1)        {if(visited[pos[now]]){break;}elsevisited[pos[now]] = 1;now = (now - (pos[now])+10*cnt)%cnt;cnt2++;}if(now==cnt-1&&cnt2==cnt)return 1;return 0;}int main() {int num;fin >> num;while(1){        memset(visited, 0, sizeof(visited));num++;//cout<<"part1\n";if(check(num)){fout << num <<endl;break;}}    return 0;}


0 0