第九周第三天

强化学习是一种机器学习方法,通过与环境的交互来学习最佳策略。在强化学习框架中,代理观察环境的状态并采取相应的行动以获得奖励或惩罚。代理的目标是通过不断的探索和学习找到一种策略,使长期累积回报最大化。与监督学习不同,强化学习通常不依赖于大量的标记数据,而是通过反复试验来提高决策能力。强化学习在许多复杂的任务中取得了成功,如机器人控制、自动驾驶和游戏人工智能。在著名的围棋程序AlphaGo中,强化学习与深度神经网络相结合,使计算机能够达到甚至超过顶级人类棋手的水平。然而,在实际应用中,强化学习仍然面临着样本效率低、训练成本高等挑战。

49

#include<bits/stdc++.h>

using namespace std;

void insertSort(int arr[],int n){

for(int i=1;i<n;i++){

int key=arr[i];

int j=i-1;

while(j>=0&&key<arr[j]){

arr[j+1]=arr[j];

j--;

}

arr[j+1]=key;

}

}

int main(){

int m,c;//m代表木板数,c代表牛棚数

scanf("%d %d",&m,&c);

vector<int> a(c);

for(int i=0;i<c;i++){

scanf(" %d",&a[i]);

}

insertSort(a.data(),c);

vector<int> arr(c-1);

for(int i=0;i<c-1;i++){

arr[i]=a[i+1]-a[i]-1;

}

insertSort(arr.data(),c-1);

int total=c;

for(int i=0;i<c-m;i++){

total+=arr[i];

}

printf("%d",total);

return 0;

}

50

#include <iostream>

#include <set>

using namespace std;

int main() {

int n;

// 循环读取多组测试数据

while (cin >> n) {

set<long long> s; // 使用set自动去重和排序,long long防止溢出

long long num;

for (int i = 0; i < n; i++) {

cin >> num;

s.insert(num); // 插入进去,set会自动去重排序

}

// 遍历set输出结果

bool first = true; // 控制空格输出

for (auto it = s.begin(); it != s.end(); it++) {

if (!first) cout << " "; // 不是第一个数,先打印空格

cout << *it;

first = false;

}

cout << endl; // 每组结果换行

}

return 0;

}

51

#include<bits/stdc++.h>

int main(){

int left[101],right[101];

while(scanf("%d %d",&left[1],&right[1])!=EOF){

int count=1;

while(left[count]!=1){

left[count + 1]=left[count]/2;

right[count + 1]=right[count]*2;

count++;

}

int total=0;

for(int i=1;i<=count;i++){

if(left[i]%2==1){

total+=right[i];

}

}

printf("%d*%d=",left[1],right[1]);

int flag=0;

for(int i =1;i<=count;i++){

if(left[i]%2==1){

if(flag){

printf("+");

}

flag=1;

printf("%d",right[i]);

}

}

printf("=%d\n",total);

}

}

相关推荐
smj2302_796826522 小时前
解决leetcode第3943题递增后的数对数量
数据结构·python·算法·leetcode
炽烈小老头3 小时前
【每天学习一点算法 2026/05/25】矩阵中的最长递增路径
学习·算法·矩阵
叁散4 小时前
实验报告:5G 仿真环境与基本链路模拟
算法
从负无穷开始的三次元代码生活5 小时前
算法零碎灵感点分享
算法
染指11105 小时前
9.LangChain框架(实现RAG)
数据库·人工智能·算法·机器学习·ai·大模型
大数据三康5 小时前
在spyder进行的遗传算法练习
开发语言·python·算法
Gene_20225 小时前
轮式底盘的微分平坦
算法
吴佳浩6 小时前
现代多模态大模型的核心基础:Unified Self-Attention
人工智能·算法·llm
小小编程路6 小时前
C++ 常用逻辑运算符
开发语言·c++·算法
Hali_Botebie6 小时前
两种子词分词算法BPE (Byte-Pair Encoding) 和Unigram 区别
人工智能·算法