您的位置:首页 > 其它

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: