zoukankan      html  css  js  c++  java
  • (Problem 62)Cubic permutations(待续)

    The cube, 41063625 (3453), can be permuted to produce two other cubes: 56623104 (3843) and 66430125 (4053). In fact, 41063625 is the smallest cube which has exactly three permutations of its digits which are also cube.

    Find the smallest cube for which exactly five permutations of its digits are cube.

    题目大意:

    立方数 41063625 (3453) 通过排列可以得到两个另外的立方数: 56623104 (3843) 和 66430125 (4053)。 实际上41063625是最小的三个(不多不少)排列是立方数的立方数。

    找出最小的立方数,其五个(不多不少)排列是立方数。

    #include<stdio.h>
    #include<stdbool.h>
    #include<string.h>
    #include<math.h>
    #include<stdlib.h>
    
    #define N 8000
    
    typedef struct data {
        long long n;
        char na[22];
    };
    
    struct data a[N];
    
    int cmp1(const void * a, const void * b)
    {
        struct data * c = (struct data * )a;
        struct data * d = (struct data * )b;
        return strcmp(c ->na, d ->na); 
    }
    
    int cmp2(const void * a, const void * b)
    {
        return *(char *)a - *(char *)b;
    }
    
    void solve()
    {
        int i, j;
        long long t, min;
        min = 10000000000000000000;
        for(i = 0, j = 333; i < N; i++, j++) {
            a[i].n = j * j * j;
            sprintf(a[i].na, "%lld", a[i].n);
            qsort(a[i].na, strlen(a[i].na), sizeof(char), cmp2);
        }
        qsort(a, N, sizeof(a[0]), cmp1);
    
        for(int i = 0; i < N; i++) {
            if(strcmp(a[i].na, a[i + 1].na) == 0 && strcmp(a[i].na, a[i + 2].na) == 0 &&
                strcmp(a[i].na, a[i + 3].na) == 0 && strcmp(a[i].na, a[i + 4].na) == 0 ) {
                printf("%lld
    %lld
    %lld
    %lld
    %lld
    ", a[i].n, a[i + 1].n, a[i + 2].n, a[i + 3].n, a[i + 4].n);
                
            }
        }
        //printf("%lld
    ", min);
    }
    
    int main()
    {
        solve();
        return 0;
    }
  • 相关阅读:
    html_dom类读取
    PHPExcel读取Excel文件的实现代码
    PHP中的mb_convert_encoding与iconv函数介绍
    BZOJ 3160 万径人踪灭 解题报告
    BZOJ 4036 [HAOI2015] Set 解题报告
    BZOJ 3288 Mato矩阵 解题报告
    BZOJ 3173 [Tjoi2013] 最长上升子序列 解题报告
    BZOJ 4123 [Baltic2015] Hacker 解题报告
    BZOJ 4127 Abs 解题报告
    BZOJ 4145 [AMPPZ2014] The Prices 解题报告
  • 原文地址:https://www.cnblogs.com/acutus/p/3551642.html
Copyright © 2011-2022 走看看