usaco-2.2-runaround-pass

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

/*
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!
时间: 2024-09-09 02:48:33

usaco-2.2-runaround-pass的相关文章

USACO Section2.2 Runaround Numbers 解题报告 【icedream61】

runround解题报告------------------------------------------------------------------------------------------------------------------------------------------------[题目] 给你一个数M,找出第一个比它大的循环数. 循环数:不包括0.没有重复数字,并且有循环性质的正整数. 循环性质:以81362为例 1.找到最高位,是8,那么往下数8位,依次是1,3

USACO runaround

/* ID:kevin_s1 PROG:runround LANG:C++ */ #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <vector> #include <map> #include <set> #include <algorithm> #include <cstdlib&g

USACO Section 2.2 Runaround Numbers

/* ID: lucien23 PROG: runround LANG: C++ */ #include <iostream> #include <fstream> #include <cstring> using namespace std; int main() { ifstream infile("runround.in"); ofstream outfile("runround.out"); if(!infile || !

USACO Runaround Numbers 模拟

根据题意的 Runaround 规则去找比当前数大的最近的一个 Runaround数字 模拟题~ Source code: /* ID: wushuai2 PROG: runround LANG: C++ */ //#pragma comment(linker, "/STACK:16777216") //for c++ Compiler #include <stdio.h> #include <iostream> #include <fstream>

usaco Runaround Numbers

题意为一个数从最左边开始,往右数这个位上的个数个,然后这样走一圈,回到起点,每个数字都访问过且只访问一次,这个数字就是循环数 要求找出第一个比N大的循环数 /* ID: modengd1 PROG: runround LANG: C++ */ #include <iostream> #include <math.h> #include <stdio.h> #include <memory.h> using namespace std; bool isarro

【USACO 2.2】Runaround Numbers

找出第一个大于n的数满足:每一位上的数都不同,且没有0,第一位开始每次前进当前这位上的数那么多位,超过总位数就回到开头继续往前进,最后能不能每个位都到过一次且回到第一位,$n<10^9$. 暴力,每次n++后模拟一边判断是否符合条件. /* TASK:runround LANG:C++ */ #include<cstdio> #include<cstring> using namespace std; int n; int get(int now,int step,int l

Usaco Open09 Gold

Problem 1: Ski Lessons [Brian Jacokes, 2002] Farmer John wants to take Bessie skiing in Colorado. Sadly, Bessie is not really a very good skier. Bessie has learned that the ski resort is offering S (0 <= S <= 100) ski classes throughout the day. Les

COGS 696. [IOI1996][USACO 2.3] 最长前缀

★   输入文件:prefix.in   输出文件:prefix.out   简单对比时间限制:1 s   内存限制:128 MB 描述 USACO 2.3.1 IOI96 在生物学中,一些生物的结构是用包含其要素的大写字母序列来表示的.生物学家对于把长的序列分解成较短的序列(即元素)很感兴趣. 如果一个集合 P 中的元素可以通过串联(元素可以重复使用,相当于 Pascal 中的 “+” 运算符)组成一个序列 S ,那么我们认为序列 S 可以分解为 P 中的元素.元素不一定要全部出现(如下例中B

USACO prefix TrieTree + DP

/* ID:kevin_s1 PROG:prefix LANG:C++ */ #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <vector> #include <map> #include <set> #include <algorithm> #include <cstdlib>

【USACO 1.3.4】牛式

[題目描述 ] 下面是一个乘法竖式,如果用我们给定的那n个数字来取代*,可以使式子成立的话,我们就叫这个式子牛式. * * * x * * ---------- * * * * * * ---------- * * * * 数字只能取代*,当然第一位不能为0,况且给定的数字里不包括0. 注意一下在美国的学校中教的"部分乘积",第一部分乘积是第二个数的个位和第一个数的积,第二部分乘积是第二个数的十位和第一个数的乘积. 写一个程序找出所有的牛式. [格式] INPUT FORMAT: (f