码迷,mamicode.com
首页 > 其他好文 > 详细

usaco-2.2-runaround-pass

时间:2014-09-04 14:43:29      阅读:200      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   os   io   ar   for   div   sp   

这个题意,呵呵,要理解清楚:

/*
ID: qq104801
LANG: 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: runround
LANG: C++

Compiling...
Compile: OK

Executing...
   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 ----
9000000

Keep up the good work!
Thanks for your submission!

 

usaco-2.2-runaround-pass

标签:style   blog   color   os   io   ar   for   div   sp   

原文地址:http://www.cnblogs.com/dpblue/p/3955922.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!