2.2Runaround Numbers
2010-11-25 14:27
239 查看
因为每位的数字都是唯一的,所以先从1到9位回溯构造数字,然后判断是否runaround
#include<iostream> #include<fstream> #include<string> #include<memory.h> #include<cstdio> #include<cmath> #include<algorithm> #include<queue> #include<vector> using namespace std; ifstream fin("runround.in"); ofstream fout("runround.out"); int n,now; char num[10]; bool used[10]; int val[1000000]; int vi=0; bool check(){ bool read[10]; memset(read,false,sizeof(read)); int ri=0; read[ri]=true; int sta,end; sta=num[0]; while(1){ ri=(num[ri]-'0'+ri)%now; if(read[ri]){ end=num[ri]; break;} read[ri]=true; } if(sta!=end) return false; for(int i=0;i<now;i++){ if(!read[i]) return false; } return true; } void make(int dep){ if(dep==now){ if(check()){ int tmp=0; int wei=1; for(int i=now-1;i>=0;i--){ tmp+=(wei*(num[i]-'0')); wei*=10; } val[vi++]=tmp; } return ; } for(int i=1;i<10;i++){ if(!used[i]){ used[i]=true; num[dep]='0'+i; make(dep+1); used[i]=false; } } } int main(){ fin>>n; memset(used,false,sizeof(used)); for(now=1;now<10;now++){ memset(used,false,sizeof(used)); make(0); } for(int i=0;i<vi;i++){ if(n<val[i]){ fout<<val[i]<<endl;break;} } return 0; }
相关文章推荐
- USACO 2.2 Runaround Numbers (runround)
- Runaround Numbers chapter 2.2
- USACO-Section2.2 Runaround Numbers【暴力枚举】
- USACO Section 2.2 Runaround Numbers
- USACO - 2.2 Runaround Numbers(枚举)
- Section 2.2 Runaround Numbers
- USACO 2.2 Runaround Numbers
- USACO Section 2.2: Runaround Numbers
- USACO Section2.2 Runaround Numbers 解题报告 【icedream61】
- USACO - Chapter2 Section 2.2 - Runaround Numbers
- USACO-Section2.2 Runaround Numbers [其他][模拟]
- USACO 2.2 Runaround Numbers
- USACO section 2.2 Runaround Numbers
- [USACO2.2]循环数 Runaround Numbers
- [2016/7/26][usaco 2.2]Runaround Numbers
- USACO-Section2.2 Runaround Numbers
- USACO section 2.2 Runaround Numbers
- USACO 2.2 Runaround Numbers(乱搞)
- USACO 2.2 Runaround Numbers
- USACO Section 2.2 Runaround Numbers