232 条题解

  • 0
    @ 2006-10-03 12:19:16

    为什么我的程序总是只能得90分?而且不过的点是因为一组解的顺序排错了,等我把他改好,发现其他组的解又全不对了,#¥%……

    请各位高手give me a hand

    with all my thanks……

  • 0
    @ 2006-09-07 00:17:16

    狂晕....BT的题...

  • 0
    @ 2006-08-31 15:50:48

    郁闷,我1,3,9个点输出的是0.后来把seekeof改成eof就行,这是怎么回事?

  • 0
    @ 2006-08-31 14:37:59

    什么情况下我的输出会是0?我因为3个输出是0,所以没通过,70分

  • 0
    @ 2006-08-15 20:50:52

    To sunpj

    我的算法与你的相似

    这样都超时

    排列--10*9次 LENGTH(MAXLONGINT)

    计算--10次

    查找--不超过20次



    那该怎么办呢?

    怎么优化 ;

    大牛们 指点一下拉

    还有第七个数据是什么

    怎么会错呢?

    好象都不对啊

  • 0
    @ 2006-06-06 17:44:09

    用字符串代替数租存储数字、进行数字排序,速度更快,更易编写!

    另外,虽然输入数字不超过longint但是排序之后可能超过,所以应该用int64来存储运算数。

  • 0
    @ 2006-01-26 09:58:29

    注意数据范围..

    虽说是到maxlongint

    可是随便给取个最大顺序排一下就超出范围了

    用int64

  • 0
    @ 2006-01-22 19:45:00

    简单模拟就行了。

    用一个数组(我用的字符串)存以前所有的情况,然后每生成一种情况就和前面的比较。

    有一个比较无聊的地方:就算n=maxlongint,最多也只需要模拟20次左右就可以找到解,因此数组不必开得那么大。

  • -1
    @ 2022-05-05 19:21:34
    
    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <cstring>
    #include <vector>
    #include <set>
    using namespace std;
    
    vector<string> ans;
    set<string> s;
    string now;
    int l;
    
    void init()
    {
        ans.clear();    s.clear();
    }
    
    long long getmax(string& c)
    {
        long long ans=0;
        for(int i=l-1;i>=0;i--)
            ans=(ans*10)+c[i]-'0';
        return ans;
    }
    
    long long getmin(string& c)
    {
        long long ans=0;
        for(int i=0;i<l;i++)
            ans=(ans*10)+c[i]-'0';
        return ans;
    }
    
    string tostring(long long x)
    {
        char a[1000];
        int l=0;
        while(x)
        {
            a[l++]=x%10+'0';
            x/=10;
        }
        a[l]='\0';
        string c(a);
        reverse(c.begin(),c.end());
        return c;
    }
    
    int main()
    {
        while(cin>>now)
        {
            init();
            while(!s.count(now))
            {
                s.insert(now);  ans.push_back(now);
                sort(now.begin(),now.end());
                l=now.length();
                long long a=getmax(now);    long long b=getmin(now);
                now=tostring(a-b);
            }
            ans.push_back(now);
            int k=0;    while(ans[k]!=now)  k++;
            cout<<ans[k]<<" ";
            while(ans[++k]!=now)
                cout<<ans[k]<<" ";
            cout<<endl;
        }
        return 0;
    }
         
    
    
    
  • -1
    @ 2018-09-15 15:49:53
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <algorithm>
    #include <math.h>
    bool cmp1( int a, int b)
    {
        return a > b;
    }
    unsigned long long int calculate(unsigned long long int num) {
        unsigned long long int min, max, i, cha;
        char s[100];
        for (i = 0; num > 0; i++) {
            s[i] = num % 10 + '0';
            num /= 10;
        }
        std::sort(s, s + (i > 4 ? i : 4));
        min = atoll(s);
        std::sort(s, s + (i > 4 ? i : 4), cmp1);
        max = atoll(s);
        cha = max - min;
        if (cha == 0) return min;
        if (cha < 10) cha *= 1000;
        else if (cha < 100) cha *= 100;
        else if (cha < 1000) cha *= 10;
        return cha;
    }
    int check(unsigned long long int *p, int n) {
        int i, j;
        for (i = 0; i < n; i++) {
            if (*(p + n) == *(p + i)) {
                for (j = i; j < n; j++) {
                    printf("%lld ", *(p + j));
                }
                return 1;
            }
        }
        return 0;
    }
    int main(void)
    {
        int i;
        unsigned long long int num, loop[100];
        while (scanf("%lld", &num) != EOF) {
            loop[0] = num;
            for (i = 0; i < 99; i++) {
                loop[i + 1] = calculate(loop[i]);
                if (check(loop, i + 1)) {
                    printf("\n");
                    break;
                }
            }
    
        }
    
        return 0;
    }
    
  • -1
    @ 2016-10-07 14:48:49

    #include<iostream>
    using namespace std;

    int main()
    {
    return 0;
    }

  • -1
    @ 2016-10-05 17:00:53

信息

ID
1024
难度
6
分类
模拟 点击显示
标签
(无)
递交数
6785
已通过
1570
通过率
23%
被复制
15
上传者