Usaco runaround Numbers

Source: Internet
Author: User

Test instructions for a number from the left, to the right number of the number of this bit, and then walk around, back to the starting point, each number has been accessed and accessed only once, this number is the number of loops

Ask to find the first number of loops larger than n

/*id:modengd1prog:runroundlang:c++*/#include <iostream> #include <math.h> #include <stdio.h># Include <memory.h>using namespace Std;bool isarroud (int x) {    int a[20];    int size=0;    BOOL VIS[10];    memset (vis,false,sizeof (Vis));    for (size=0;x>0; size++)    {        a[size+1]=x%10;        if (a[size+1]==0)            return false;        if (Vis[a[size+1]])            return false;        Vis[a[size+1]]=true;        x/=10;    }    int tag=0,i;    Because of the relationship of the direction stored in the A array, I represents the number of digits from left to right, but the a[size in the array for the I-bit number] position for    (i=0;! (tag&1<<i); i= (I+a[size-i])%size)        tag|=1<<i;    if (tag== (1<<size) -1&&i==0)        return true;    return false;} int main () {    freopen ("runround.in", "R", stdin);    Freopen ("Runround.out", "w", stdout);    int N;    scanf ("%d", &n);    while (n++)    {        if (Isarroud (N)) is break            ;    }    cout<<n<<endl;    return 0;}

  

Usaco runaround Numbers

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.