3.16打卡day30

127.我素故我在

问题描述

有这样一种素数叫纯素数(YY出来的名字),当它是一个多位数的时候,你把它的末位去掉之后余下的数依然是一个素数。比如说2393,2393 本身是一个素数,它的末位去掉之后,余下的是239。239 是一个素数,它的末位去掉之后,余下的是23 。23是一个素数,它的末位去掉之后,余下的是2 。2依然还是一个素数。纯素数的长度叫做"维"。2393 是一个4维素数。3797也是一个4维素数。

个人总结

本题用DFS可以做,从 1 位素数开始(2,3,5,7),逐位向后添加数字(只能是 1,3,5,7,9,因为末位不能是偶数或 5 才能保证新数可能是素数),并检查新数是否为素数。用 DFS 生成所有 T 位的纯素数,最后排序输出。

cpp 复制代码
#include <bits/stdc++.h>
using namespace std;

bool isPrime(int x){
    if (x<=1) return false;
    if (x==2) return true;
    if (x%2==0) return false;
    for (int i = 3; i <= sqrt(x); i+=2) {
        if (x%i==0) return false;
    }
    return true;
}
//深度优先搜索 生成T维纯素数
void dfs(int current, int length, int T, vector<int>& result){
    if (length==T){
        result.push_back(current);
        return;
    }
    // 接下来可以添加的数字:1,3,5,7,9(因为不能是偶数或5才能继续是素数)
    int nextDigits[]={1,3,5,7,9};
    for (int d: nextDigits) {
        int nextNum = current*10+d;
        if (isPrime(nextNum)){
            dfs(nextNum,length+1,T,result);
        }

    }
}

int main() {
    int n;
    cin>>n;
    while (n--){
        int T;
        cin>>T;
        vector<int> result;
        //一位纯素数
        int oneDigitPrimes[]={2,3,5,7};
        for (int p: oneDigitPrimes) {
            dfs(p,1,T,result);
        }
        sort(result.begin(),result.end());
        for (int i = 0; i < result.size(); ++i) {
            cout<<result[i]<<endl;
        }
    }
    return 0;
}

128.汉诺塔问题的第m步

问题描述

给定三根杆A、B、C和大小不同的几个盘子。这些盘子按尺寸递减顺序套在A杆上,最小的在最上面。现在的任务是把这些盘子从A杆移到C杆且保持原来堆放顺序。在实现任务时,每次只能移动一个盘子,且任何时刻不允许大的盘子放在小的盘子上面,B杆可以作为辅助存放杆。求:总共有n个圆盘时,搬动过程中的第m步是从哪个杆到哪个杆。

个人总结

汉诺塔问题可以用递归解决:要把 n 个盘子从 A 移到 C,借助 B。先把上面 n-1 个盘子从 A 移到 B,再借助 C把最大的盘子从 A 移到 C,最后把 n-1 个盘子从 B 移到 C,借助 A。记录当前是第几步,当步数等于 m 时,输出移动过程。

cpp 复制代码
#include <bits/stdc++.h>
using namespace std;

int step;        // 当前步数
int target;      // 要找的第 m 步
bool found;      // 是否已找到
string moveStr;  // 记录找到的移动

// 汉诺塔递归模拟   n:要移动的盘子数;  from:源杆;   to:目标杆;    aux:辅助杆
void hanoi(int n, char from, char to, char aux) {
    if (found) return;        // 已经找到,不再继续

    if (n == 1) {
        step++;
        if (step == target) {
            moveStr = string(1, from) + "--" + string(1, to);
            found = true;
        }
        return;
    }

    // 先把 n-1 个盘子从 from 移到 aux
    hanoi(n - 1, from, aux, to);

    if (found) return;

    // 移动最大的盘子
    step++;
    if (step == target) {
        moveStr = string(1, from) + "--" + string(1, to);
        found = true;
        return;
    }

    // 再把 n-1 个盘子从 aux 移到 to
    hanoi(n - 1, aux, to, from);
}

int main() {
    int n, m;
    while (cin >> n >> m) {
        step = 0;
        target = m;
        found = false;
        moveStr = "";

        hanoi(n, 'A', 'C', 'B');

        if (found) {
            cout << moveStr << endl;
        } else {
            cout << "none" << endl;
        }
    }
    return 0;
}

129.数字游戏

问题描述

现在,有许多给小孩子玩的数字游戏,这些游戏玩起来简单,但要创造一个就不是那么容易的了。 在这,我们将介绍一种有趣的游戏。

你将会得到N个正整数,你可以将一个整数接在另一个整数之后以制造一个更大的整数。 例如,这有4个数字123, 124, 56, 90,他们可以制造下列整数─ 1231245690, 1241235690, 5612312490, 9012312456, 9056124123....等,总共可以组合出24(4!)种数字。 但是,9056124123是最大的那一个。

你可能会想这是个简单的事情,但对刚有数字概念小孩来说,这会是个简单的任务吗?

个人总结

本题不是按数字大小排序,而是按拼接后的结果排序。把所有数字转换成字符串,如果 a + b > b + a,则 a 应该排在 b 前面,按此规则排序,然后依次拼接。

cpp 复制代码
#include <bits/stdc++.h>
using namespace std;

bool cmp(const string& a, const string& b) {
    return a + b > b + a;
}

int main() {
    int N;
    while (cin >> N && N != 0) {
        vector<string> nums(N);
        for (int i = 0; i < N; i++) {
            cin >> nums[i];
        }

        sort(nums.begin(), nums.end(), cmp);

        for (const string& s : nums) {
            cout << s;
        }
        cout << endl;
    }
    return 0;
}

计算机英语翻译

原文:

Convolutional neural networks (CNNs) are among the most important models in deep learning and are widely used in computer vision tasks such as image classification, object detection, and image segmentation. Compared with traditional fully connected neural networks, CNNs significantly reduce the number of parameters by using local connections and weight sharing, which lowers computational complexity. Convolutional layers can automatically extract features from raw images, including edges, textures, and shapes. As the number of layers increases, the model is able to learn more abstract and complex feature representations. In addition, pooling layers are usually used to reduce the spatial dimensions of feature maps, thereby decreasing computational cost and improving robustness. In practical applications, CNNs have achieved remarkable success in areas such as medical image analysis, autonomous driving, and face recognition. However, training deep convolutional neural networks often requires large amounts of labeled data and powerful computing resources, which remains an important challenge in current research.

翻译

卷积神经网络是深度学习中最重要的模型之一,广泛应用于计算机视觉任务,例如图像分类、事物探测和图像分割。和传统的全连接神经网络相比,CNNs通过使用本地连接和重量分享显著减少了参数的数量,降低了计算的复杂性。卷积层能自动从原始图像中提取特征,包括边界、文本和形状。随着层数的增加,模型能学习更抽象和复杂的特征代表。此外,xx层通常用于减少特征图的空间维度,从而降低计算费用和提升xx。在实际应用中,CNNs已经在医学图像分析、自动驾驶和人脸识别等领域取得重大成功。然而,训练深度卷积神经网络通常需要大量的标注数据和强大的计算资源,这仍是当前研究中的重大挑战。

计算机英语单词扇贝打卡

相关推荐
学习星球1 分钟前
空天地一体化网络(NTN)深度解析:从Starlink D2C到3GPP NTN,卫星直连手机是如何实现的?
网络·人工智能·算法·智能手机·php
科技林总12 分钟前
提示词测评落地全流程
人工智能·算法
Chester_199924 分钟前
CSP202206C.角色授权
开发语言·数据结构·c++·蓝桥杯
艾莉丝努力练剑26 分钟前
【AI大模型接入SDK】WebSocket & SSE 协议
网络·c++·websocket·网络协议·学习·面试
码匠许师傅27 分钟前
【设计模式精讲】6.抽象工厂(Abstract Factory)
c++·设计模式
GKxx29 分钟前
在 HarmonyOS 上从源码构建 GCC 16(gcc/g++ + libstdc++ + libsanitizer):完整记录
c++·华为·harmonyos·鸿蒙·gcc
晴天的雨.99231 分钟前
类和对象下(内部类,匿名对象,对象拷贝时的编译器优化)
开发语言·c++·算法
旖旎夜光1 小时前
LeetCode 238:除自身以外数组的乘积(前缀和) —— 题解
数据结构·c++·算法·leetcode·前缀和
一条大祥脚1 小时前
26杭电暑期第八场(后半)快读|快写|tarjan|路径DP|mex转化|扫描线|前缀和|二分图
数据结构·算法·tarjan·杭电多校·强联通分量·动态规划dp
奈斯先生Vector1 小时前
从“能调用”到“可运营”:AI Agent 进入多模型时代后的架构升级
java·javascript·数据库·人工智能·算法·架构·aigc