首页 > 代码库 > usaco-2.2-runaround-pass
usaco-2.2-runaround-pass
这个题意,呵呵,要理解清楚:
/*ID: qq104801LANG: C++TASK: runround*/#include <iostream>#include <fstream>#include <cstring>#include <vector>#include <cstdio>#include <algorithm>using namespace std;int n;void numtostr(int x,char *s){ int i=0; while(x) { s[i++]=x%10+‘0‘; x/=10; } s[i]=‘\0‘; int j=i-1; i=0; while(i<j)swap(s[i++],s[j--]);}bool judge(int x){ int len,i,p; char str[10]; bool visited[10]; numtostr(x,str); len=strlen(str); memset(visited,false,sizeof(visited)); p=0; while (!visited[p]) { visited[p]=true; p=(p+str[p]-‘0‘)%len; } if(p) return false; for(i=0;i<len;i++) if(!visited[i]) return false; sort(str,str+len); for(i=0;i<len-1;i++) if(str[i]==str[i+1])return false; return true;}void test(){ freopen("runround.in","r",stdin); freopen("runround.out","w",stdout); cin>>n; int i; for(i=n+1;!judge(i);i++); cout<<i<<endl; }int main () { test(); return 0;}
test data:
USER: cn tom [qq104801]TASK: runroundLANG: C++Compiling...Compile: OKExecuting... Test 1: TEST OK [0.008 secs, 3376 KB] Test 2: TEST OK [0.022 secs, 3376 KB] Test 3: TEST OK [0.005 secs, 3376 KB] Test 4: TEST OK [0.008 secs, 3376 KB] Test 5: TEST OK [0.068 secs, 3376 KB] Test 6: TEST OK [0.016 secs, 3376 KB] Test 7: TEST OK [0.086 secs, 3376 KB]All tests OK.Your program (‘runround‘) produced all correct answers! This is your submission #2 for this problem. Congratulations!Here are the test data inputs:------- test 1 ----99------- test 2 ----111110------- test 3 ----134259------- test 4 ----348761------- test 5 ----1000000------- test 6 ----5000000------- test 7 ----9000000Keep up the good work!Thanks for your submission!
usaco-2.2-runaround-pass
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。