CF1916D. Mathematical Problem

题目链接:Problem - 1916D - Codeforces

打表看下有满足答案的组成集合

打表程序如下:

//
// Created by Botter on 2024/5/11.
//

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
int w(ll x){
    int cnt =0;
    while (x){
        cnt++;
        x/=10;
    }
    return cnt;
}
int main() {
    map<int,vector<ll>>m;
    for (ll i = 1 ; ; i++){
        if (i*i >= INT_MAX-1) break;
        m[w(i*i)].push_back(i*i);
    }
    int t,n,ans=0;
    cin >>t;
    map<set<int>,int>s;
    while(t--){
        cin >>n;
        set<int>a;
        for (int i = 0;i<m[n].size();i++){
            int t = m[n][i];
            while(t){
                a.insert(t%10);t/=10;
            }
            ans=max(ans,++s[a]);a.clear();
        }
        cout << ans<<endl;
        for (auto [_,v]:s){
            if (s[_] >= n) {
                for (auto c: _) {
                    cout << c;
                }
                cout << " " << s[_] << endl;
            }
        }
    }
    return 0;
}

思路即实现:

通过输出,找了找,满足答案的集合里都有这样这个集合{0,1,6,9}。也就是说那么答案一定是由这个集合组成的,即若干0和1,6,9组成的数。我们还可以发现169,196,以及961都是可以平方数,那么我们在末尾添加n-3个0那么也一定是平方数,因为n是奇数。那么我们试试在中间添加相同个数零试试,不难发现10..60..9  一定是可以被10.. ..3平方的。196和961同理;我们前面输出了3种,可以添加0的情况一定有[0,\frac{n-1}{2}],事实上已经满足n种了。枚举169和961两种\tfrac{}{}就可以了。

代码实现:

//
// Created by Botter on 2024/5/11.
//

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
void slove(){
    int n;
    cin >> n;
    if (n==1) {
        cout << 1<<endl;
        return;
    }
    //全补零的三个数(3)
    cout << "169";
    for (int i = 4 ; i <= n ; i++) cout << "0";
    cout << endl;
    cout << "196";
    for (int i = 4 ; i <= n ; i++) cout << "0";
    cout << endl;
    cout << "961";
    for (int i = 4 ; i <= n ; i++) cout << "0";
    cout << endl;
    for(int i = 1 ; i < n/2;i++){
        cout << 1;
        for (int j = 1;j <= i ; j++) cout << 0;
        cout << 6;
        for (int j = 1 ; j <= i ; j++) cout << 0;
        cout << 9;
        for (int j = 3+2*i;j<n;j++)cout << 0;
        cout << endl;
        cout << 9;
        for (int j = 1;j<=i;j++) cout << 0;
        cout <<6;
        for (int j = 1;j<=i;j++) cout <<0;
        cout << 1;
        for (int j=3+2*i;j<n;j++) cout << 0;
        cout << endl;
    }
}
bool isovle(int x){
    return sqrt(x)==int(sqrt(x));
}
int main() {
    int t,n,ans=0;
    cin >>t;
    while(t--){
        slove();
    }
//    cout << isovle(169)<<isovle(196)<<isovle(961);
    return 0;
}

  • 9
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值