In 2017, the 8th Blue Bridge Cup Java Programming Undergraduate Group B final square ten digits (result fill in the blank)

 

2017 8th Blue Bridge Cup Java Programming Undergraduate Group B Final Individual Problem Solution Summary:

https://blog.csdn.net/daixinliangwyx/article/details/90184941

 

first question

Title: Squared Tens

The 10 numbers from 0 to 9 are not repeated or omitted, and many 10-digit numbers can be formed.
Many of these also happen to be squares (the square of a number).

For example: 1026753849, which is the smallest square number.

Could you please find out what is the largest square number among them?

Note: What you need to submit is a 10-digit number, don't fill in any extras.


Solution: Use the full permutation function to run directly, and continuously update the square number. When the full permutation is finished, the square number obtained must be the largest.

Code:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  ll num[10], maxn = 0;
  for (ll i = 0; i < 10; i++)
    num[i] = i;
  do {
    ll a = 0, tmp;
    for(ll i = 0; i < 10; i++)
      a = a * 10 + num[i];
    tmp = sqrt(a);
    if(tmp * tmp == a) maxn = a;
  } while (next_permutation(num, num+10));
  cout << maxn << endl; 
  return 0;
}

Answer: 9814072356 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326525998&siteId=291194637