Square Number of squares

Source: Internet
Author: User

Square number

0~9 these 10 numbers into groups, each group happens to be a square number, which can be done.
For example: 0, 36, 5948721

Another example:
1098524736
1, 25, 6390784
0, 4, 289, 15376.
Wait a minute...

Note that 0 can be used as a separate number, but not as a start for multiple digits.
When grouping, you must run out of all the numbers, you cannot repeat them, you cannot omit them.

If you do not care about the order of the data in the group, how many different groups of options.

Note: You need to submit an integer, do not fill out the extra content.

Answer: 300

Run in full order, four seconds, here I use the Set container to check the weight, to convert multiple numbers to string type when you should pay attention to standardization, that is, sorting, can not directly operate on the original array, every two number plus a spacer

#include "iostream" #include "algorithm" #include "string.h" #include "math.h" #include <map> #include <set>
using namespace Std;
Long Long shu[20];
int ai[10]={0,1,2,3,4,5,6,7,8,9};

Set<string> JJ;
        void dfs (int cur,int num) {if (cur==10) {long long shu2[20];
        for (int i=0;i<num;i++) shu2[i]=shu[i];
        Sort (shu2,shu2+num);

        String Xu;
                for (int i=0;i<num;i++) {while (shu2[i]) {int a=shu2[i]%10;
                SHU2[I]=SHU2[I]/10;
                Char b=a+ ' 0 ';
            Xu=xu+b; 
        } xu+= '-';
        } jj.insert (Xu);
    return;
        } if (ai[cur]==0) {shu[num]=0;
    DFS (CUR+1,NUM+1);
        else {long long sum=0;
            for (int i=cur;i<10;i++) {sum=sum*10+ai[i];
            Double son=sqrt (sum); if (son== (int) son) {Shu[num]=sUm
            DFS (I+1,NUM+1);
        int main () {do {memset (shu,0,sizeof (SHU));
    DFS (0,0);
    }while (Next_permutation (ai,ai+10));
    Cout<<jj.size () <<endl;
return 0; }

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.