USACO 2.2.3 Runaround Numbers
2015-09-29 23:29
316 查看
暴力枚举+模拟验证,注意判断条件
#include <iostream> #include <fstream> #include <string> #include <map> #include <string.h> #define LL long long //#define LOCAL using namespace std; #ifdef LOCAL ofstream fout ("out.txt"); ifstream fin ("in.txt"); #else ofstream fout ("runround.out"); ifstream fin ("runround.in"); #endif int 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; } else visited[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; }
相关文章推荐
- 求二叉树最长路径和
- C#面向对象设计模式纵横谈——1.面向对象设计模式与原则
- light oj 1379 - Toll Management(两次最短路)
- 循环队列ADT_SeqQueue
- UI综合
- 键盘按键ASCII码值与ASCII表
- 玩转oracle(3)_韩顺平
- angular中的异常机制与异常之外的处理
- UVALive 6885 spfa
- 高等数学(1)
- C#定时器,定时做什么事情
- UVALive 6885 spfa
- 策略模式
- pat 1097 Deduplication on a Linked List
- JAVA堆栈操作
- hdu 1142 A Walk Through the Forest spfa
- RazorSQL 注册码
- hdu 1142 A Walk Through the Forest spfa
- (转)JAVA堆栈操作
- postgreSQL格式化时间的函数详解