【USACO 2.2】Runaround Numbers
2016-10-18 23:28
302 查看
找出第一个大于n的数满足:每一位上的数都不同,且没有0,第一位开始每次前进当前这位上的数那么多位,超过总位数就回到开头继续往前进,最后能不能每个位都到过一次且回到第一位,$n<10^9$。
暴力,每次n++后模拟一边判断是否符合条件。
暴力,每次n++后模拟一边判断是否符合条件。
/* TASK:runround LANG:C++ */ #include<cstdio> #include<cstring> using namespace std; int n; int get(int now,int step,int len){ return (now+step-1)%len+1; } bool ck(){ char s[11]; sprintf(s+1,"%d",n); int now=1; int len=strlen(s+1); bool v[11],used[11]; memset(v,0,sizeof v); memset(used,0,sizeof used); used[0]=1; //printf("%d:",n); for(int i=0;i<len;i++){ if(used[s[now]-'0']||v[now]) return 0; used[s[now]-'0']=v[now]=1; //printf("%d %c\n",now,s[now]); now=get(now,s[now]-'0',len); } return now==1; } int main(){ freopen("runround.in","r",stdin); freopen("runround.out","w",stdout); scanf("%d",&n); n++; while(!ck())n++; printf("%d\n",n); return 0; }
相关文章推荐
- USACO 2.2 Runaround Numbers
- USACO - Chapter2 Section 2.2 - Runaround Numbers
- USACO-Section2.2 Runaround Numbers【暴力枚举】
- USACO 2.2 Runaround Numbers
- USACO 2.2 Runaround Numbers (runround)
- [USACO2.2]循环数 Runaround Numbers
- USACO-Section2.2 Runaround Numbers
- [2016/7/26][usaco 2.2]Runaround Numbers
- USACO-Section2.2 Runaround Numbers [其他][模拟]
- USACO Section2.2 Runaround Numbers 解题报告 【icedream61】
- USACO - 2.2 Runaround Numbers(枚举)
- USACO-Section 2.2 Runaround Numbers (枚举)
- USACO 2.2 Runaround Numbers
- USACO 2.2 Runaround Numbers(乱搞)
- Section 2.2 Runaround Numbers
- Runaround Numbers chapter 2.2
- [USACO 2.2.3] Runaround Numbers
- usaco training-Runaround Numbers
- 【其他】【USACO】Runaround Numbers
- USACO2.2.3 Runaround Numbers (runround)