zoukankan      html  css  js  c++  java
  • [蓝桥杯] 排它平方数

    [蓝桥杯] 排它平方数

    【题目描述 - Problem Description】

        小明正看着 203879 这个数字发呆。

        原来,203879 * 203879 = 41566646641

        这有什么神奇呢?仔细观察,203879 是个6位数,并且它的每个数位上的数字都是不同的,并且它平方后的所有数位上都不出现组成它自身的数字。

        具有这样特点的6位数还有一个,请你找出它!

        再归纳一下筛选要求:
        1. 6位正整数
        2. 每个数位上的数字不同
        3. 其平方数的每个数位不含原数字的任何组成数位

    答案是一个6位的正整数。

    【题解】

    没啥好说的,暴力枚举吧。

    【代码 C++】

     1 #include <cstdio>
     2 #include <cstring>
     3 #include <algorithm>
     4 bool w[10];
     5 bool j(__int64 now){
     6     __int64 temp;
     7     while (now){
     8         temp = now % 10, now /= 10;
     9         if (w[temp]) return false;
    10     }
    11     return true;
    12 }
    13 int main(){
    14     __int64 data[10] = { 1, 0, 2, 3, 4, 5, 6, 7, 8, 9 }, i, temp, last = 0;
    15     do{
    16         memset(w, 0, sizeof(w));
    17         for (i = temp = 0; i < 6; ++i) temp = temp * 10 + data[i], w[data[i]] = 1;
    18         if (j(temp * temp) && temp != last) printf("%I64d
    ", temp), last = temp;
    19     } while (std::next_permutation(data, data + 10));
    20     return 0;
    21 }

    【最终结果】

    639172

  • 相关阅读:
    ARC081F Flip and Rectangles
    LCA
    Tarjan
    2020牛客暑期多校六
    状压DP
    操作系统
    JAVA期末复习
    D. Yet Another Yet Another Task (区间最值)
    构造
    Codeforces Round #641 (Div. 2)
  • 原文地址:https://www.cnblogs.com/Simon-X/p/5308942.html
Copyright © 2011-2022 走看看