Home > Old Blog Posts > USACO 2.2.3 Runaround Numbers

USACO 2.2.3 Runaround Numbers


直接往后枚举吧,数据太弱了。

代码:

/*
ID: dementr1
PROG: runround
LANG: C++
*/
#include<iostream>
#include<fstream>
using namespace std;
ifstream fin(“runround.in”);
ofstream fout(“runround.out”);
bool check(int a)
{
int m=a,tmp[10],num=0,i,t[10],counter[10]={};
bool used[10];
memset(used,false,sizeof(used));
while(m>0)
{
tmp[num++]=m%10;
m/=10;
if(tmp[num-1]==0) return false;
counter[tmp[num-1]]++;
}
for(i=0;i<10;i++) if(counter[i]>1) return false;
for(i=0;i<num;i++) t[i]=tmp[num-1-i];
int now=0,counterr=0;
used[t[now]]=true;
while(counterr<num)
{
counterr++;
now=(now+t[now])%num;
if(used[t[now]]&&counterr<num-1) return false;
used[t[now]]=true;
}
if(now==0) return true;
else return false;
}
int main()
{
int i,n;
fin>>n;
i=n+1;
while(!check(i)) i++;
fout<<i<<endl;
return 0;
}

Categories: Old Blog Posts
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: