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已经在医学图像分析、自动驾驶和人脸识别等领域取得重大成功。然而,训练深度卷积神经网络通常需要大量的标注数据和强大的计算资源,这仍是当前研究中的重大挑战。

计算机英语单词扇贝打卡

相关推荐
Omics Pro几秒前
上海AI Lab孙思琦×高张阳:虚拟细胞代码库智能体
数据库·人工智能·算法·机器学习·自然语言处理
Y幽谷客5 分钟前
图像识别入门习题整理
算法
careathers14 分钟前
【数据结构】队列
java·数据结构
点纭20 分钟前
C 语言 第七章 常用函数(3)
c语言·开发语言·算法·oracle·c#
程序员老陆28 分钟前
std::experimental::when_any 深度解析:等待“第一个完成”的异步组合原语
c++·多线程
β添砖java43 分钟前
机器学习2 KNN算法、距离度量、特征预处理、超参数选择、手写数字、鸢尾花
人工智能·算法·机器学习
TAN-90°-1 小时前
Deep Learning for Computer Vision——Generative Models 2
人工智能·深度学习·神经网络·算法·目标检测·机器学习·计算机视觉
Rabitebla1 小时前
【Linux系统编程】指令(三):创建、删除、复制、移动、看内容
linux·数据结构·c++·算法
程序员老陆1 小时前
CMake 常用关键字与命令全景:从 set到 target_link_options的现代工程视角
c++·cmake·程序开发
qq_410194292 小时前
.NET 8.0 下基于 PaddleOCRSharp 的离线文字识别落地指南
算法·.net