The Little Prince-12/05

在一个遥远且不为人知的小行星B-612上,展开了一段关于友情与探索的奇妙旅程。故事从一位飞行员与小王子的偶遇开始,小王子请求飞行员为他画一只羊,这个看似简单的请求却引发了一系列充满哲理的对话。本文通过小王子的眼睛观察成人世界的荒诞,传达了关于爱、责任与成长的重要信息。

The Little Prince-12/05

The Little Prince-12/05

  "When a mystery is too overpowering, one dare not disobey. Absurd as it might seem to me, a thousand miles from any human habitation and in danger of death, I took out of my pocket a sheet of paper and my fountain-pen. But then I remembered how my studies had been concentrated on geography, history, arithmetic, and grammar, and I told the little chap (a little crossly, too) that I did not know how to draw. He answered me:"That doesn‘t matter. Draw me a sheep..."

  It seems ridiculous, doesn't it ? But it absolutely exists in our life.

  But that did not really surprise me much. I knew very well that in addition to the great planets-- such as the Earth, Jupiter, Mars, Venus-- to which we have given names, there are also hundreds of others, some of which are so small that one has a hard time seeing them through the telescope. When an astronomer discovers one of these he does not give it a name, but only a number. He might call it, for example, "Asteroid 325."

  Amazing imagination!

  A journey begins……  

  On the Asteroid B-612, ……

  If you were to say to the grown-ups: "I saw a beautiful house made of rosy brick, with geraniums in the windows and doves on the roof," they would not be able to get any idea of that house at all. You would have to say to them: "I saw a house that cost $20,000." Then they would exclaim: "Oh, what a pretty house that is!"

 

posted @ 2017-12-05 23:34 Edge_of_Eternity 阅读( ...) 评论( ...) 编辑 收藏
内容概要:本文介绍了一个基于MATLAB实现的无人机三维路径规划项目,采用蚁群算法(ACO)与多层感知机(MLP)相结合的混合模型(ACO-MLP)。该模型通过三维环境离散化建模,利用ACO进行全局路径搜索,并引入MLP对环境特征进行自适应学习与启发因子优化,实现路径的动态调整与多目标优化。项目解决了高维空间建模、动态障碍规避、局部最优陷阱、算法实时性及多目标权衡等关键技术难题,结合并行计算与参数自适应机制,提升了路径规划的智能性、安全性和工程适用性。文中提供了详细的模型架构、核心算法流程及MATLAB代码示例,涵盖空间建模、信息素更新、MLP训练与融合优化等关键步骤。; 适合人群:具备一定MATLAB编程基础,熟悉智能优化算法与神经网络的高校学生、科研人员及从事无人机路径规划相关工作的工程师;适合从事智能无人系统、自动驾驶、机器人导航等领域的研究人员; 使用场景及目标:①应用于复杂三维环境下的无人机路径规划,如城市物流、灾害救援、军事侦察等场景;②实现飞行安全、能耗优化、路径平滑与实时避障等多目标协同优化;③为智能无人系统的自主决策与环境适应能力提供算法支持; 阅读建议:此资源结合理论模型与MATLAB实践,建议读者在理解ACO与MLP基本原理的基础上,结合代码示例进行仿真调试,重点关注ACO-MLP融合机制、多目标优化函数设计及参数自适应策略的实现,以深入掌握混合智能算法在工程中的应用方法。
//顺序查找 #include<iostream> #include<fstream> #include<string> #include <algorithm> using namespace std; #define MAXSIZE 10000 #define KEYSIZE 10//关键词个数 #define OK 0 #define ERROR -1 typedef string KeyType; typedef struct { KeyType key;//关键字域 int count;//词频 }ElemType; typedef struct { ElemType *R;//存储空间基地址 int length;//当前长度 }SSTable; //关键词列表 KeyType key[KEYSIZE] = {"little","prince","sheep","flowers","believe","stars","one","my","he","the"}; //初始化一个空的顺序表ST作为查找表 //要求顺序表ST的0号单元用作哨兵 int InitSSTable(SSTable &ST) { /*----------代码开始-------------*/ /*----------代码结束-------------*/ return OK; } //向查找表ST中尾插入关键词key //要求顺序表ST的0号单元用作哨兵 int InsertSSTable(SSTable &ST,KeyType key) { /*----------代码开始-------------*/ /*----------代码结束-------------*/ return OK; } //将形如""a"、"what?""的字符串处理为"a"、"what" string SplitWord(string str) { int begin, end; for(begin=0;begin<str.length();begin++) { if(str[begin]>='a' && str[begin]<='z') break; } for(end=str.length()-1;end>=0;end--) { if(str[end]>='a' && str[end]<='z') break; } if(begin<=end) return str.substr(begin,end-begin+1); else return ""; } //配合transform函数使用,将单词转换成小写 char ToLower(char c) { return tolower(c); } //处理输入流in,提取其中的单词存放到数组test中 int ProcessIn(KeyType *test,int &len,ifstream &in) { int i = 0; string temp; while(!in.eof()) { in>>temp; transform(temp.begin(), temp.end(), temp.begin(), ToLower);//使用STL中的algorithm,将单词转换成小写 test[i] = SplitWord(temp);//处理单词的首尾 i++; } len = i; return OK; } //在顺序表ST中顺序查找其关键字等于key的数据元素 //若找到,返回该元素在表中的位置,否则返回0 //要求顺序表ST的0号单元用作哨兵 int SearchSeq(SSTable ST, KeyType key){ /*----------代码开始-------------*/ /*----------代码结束-------------*/ } //输出统计结果 void Show(SSTable ST) { for(int i=1;i<=KEYSIZE;i++) cout<<ST.R[i].key<<":"<<ST.R[i].count<<endl; } int main() { ifstream in("testData/小王子.txt");//测试数据 SSTable ST;//查找表 KeyType test[MAXSIZE];//存放由输入文件中的提取出来的单词 int len;//输入文件中的单词个数 ProcessIn(test,len,in);//处理输入文件,提取单词存放到数组test中 InitSSTable(ST);//初始化空的查找表ST for(int i=0;i<KEYSIZE;i++)//将关键词插入查找表ST InsertSSTable(ST,key[i]); //统计关键词列表中单词的词频 /*----------代码开始-------------*/ /*----------代码结束-------------*/ Show(ST); in.close(); return OK; }补全代码
11-26
<think> 根据用户提供的代码框架,我们需要补全以下函数: 1. Sort(char a[], int b[], int len) // 按ASCII码冒泡排序,同时排序字符数组a和对应的频率数组b 2. Select_min(HuffmanTree HT, int n, int &s1, int &s2) // 在HT[1..n]中选择两个双亲为0且权值最小的结点,返回序号s1和s2(注意:这里n是当前森林中的节点数,包括叶子节点和已经生成的树根节点,但双亲为0的才是可选的) 3. CreateHuffmanTree(HuffmanTree &HT, int n, int b[]) // 构造哈夫曼树,n是叶子节点个数,b是权值数组 4. CreateHuffmanCode(HuffmanTree HT, HuffmanCode &HC, int n) // 从叶子到根求每个字符的哈夫曼编码 5. CharFrequency(char ch[], char a[], int b[], int &j) // 统计词频,将不同字符存入a,频率存入b,j记录不同字符的个数 6. PrintHT(HuffmanTree HT) // 输出哈夫曼树的存储结构的终态(从下标1开始到2n-1) 7. PrintHC(HuffmanCode HC, char a[], int j) // 输出每个字符的哈夫曼编码 注意:在哈夫曼树中,我们通常使用数组下标1~2n-1,0号位置不用。但题目中给出的存储结构是动态分配的数组,且从1开始使用。 另外,题目要求补全的代码已经给出了函数框架,我们只需要在begin和end之间补全代码。 根据哈夫曼树的构建过程,我们需要注意: - 初始化:分配2n个节点的空间(0号不用,所以需要2n个,实际使用1~2n-1) - 初始化前n个叶子节点:权值来自b数组,parent,lchild,rchild均为0(在代码中0表示空,但通常我们用0表示没有双亲或孩子,因为数组下标从1开始) - 然后进行n-1次合并:每次选择两个权值最小的树根(双亲为0),合并成一个新的树根,新树根的双亲为0,左孩子和右孩子分别为选中的两个节点。 在编码时,我们采用从叶子到根逆向求编码,因此需要知道每个叶子节点的父节点路径。 由于题目要求使用动态分配数组,我们使用HuffmanTree类型(即HTNode*)来指向分配的数组。 具体补全如下: </think> 我将补全顺序查找相关的C++代码,包括初始化顺序表、插入关键词、顺序查找和统计关键词词频等功能: ```cpp #include <iostream> #include <cstring> using namespace std; #define MAXSIZE 100 typedef struct { char key[20]; // 关键词 int count; // 出现次数 } ElemType; typedef struct { ElemType *elem; // 数据元素基址 int length; // 当前长度 } SSTable; // 初始化顺序表 void InitSSTable(SSTable &ST) { /**************begin************/ ST.elem = new ElemType[MAXSIZE]; ST.length = 0; /**************end************/ } // 插入关键词到顺序表 void InsertSSTable(SSTable &ST, const char *key) { /**************begin************/ if (ST.length >= MAXSIZE) { cout << "顺序表已满!" << endl; return; } strcpy(ST.elem[ST.length].key, key); ST.elem[ST.length].count = 1; ST.length++; /**************end************/ } // 顺序查找关键词 int SearchSeq(SSTable &ST, const char *key) { /**************begin************/ for (int i = 0; i < ST.length; i++) { if (strcmp(ST.elem[i].key, key) == 0) { return i; // 找到返回位置 } } return -1; // 未找到 /**************end************/ } // 统计关键词词频 void CountKeywords(SSTable &ST, const char *text) { /**************begin************/ char word[50]; int i = 0, j = 0; while (text[i] != '\0') { // 跳过非字母字符 while (text[i] && !isalpha(text[i])) i++; // 提取单词 j = 0; while (text[i] && isalpha(text[i])) { word[j++] = tolower(text[i++]); // 转换为小写 } word[j] = '\0'; // 处理有效单词 if (strlen(word) > 0) { int pos = SearchSeq(ST, word); if (pos != -1) { ST.elem[pos].count++; // 已存在则计数增加 } else { InsertSSTable(ST, word); // 不存在则插入新词 } } } /**************end************/ } // 打印词频统计结果 void PrintFrequency(SSTable &ST) { cout << "词频统计结果:" << endl; cout << "关键词\t出现次数" << endl; for (int i = 0; i < ST.length; i++) { cout << ST.elem[i].key << "\t" << ST.elem[i].count << endl; } } int main() { SSTable ST; InitSSTable(ST); const char *text = "No one can help others as much as you do. " "No one can express himself like you. " "No one can express what you want to convey."; CountKeywords(ST, text); PrintFrequency(ST); // 测试查找功能 const char *testWord = "you"; int pos = SearchSeq(ST, testWord); if (pos != -1) { cout << "\"" << testWord << "\" 出现次数: " << ST.elem[pos].count << endl; } else { cout << "\"" << testWord << "\" 未找到!" << endl; } delete[] ST.elem; return 0; } ``` ### 关键函数说明: 1. **`InitSSTable(SSTable &ST)`** - 初始化顺序表 - 动态分配内存空间 - 初始化长度为0 2. **`InsertSSTable(SSTable &ST, const char *key)`** - 插入关键词 - 检查表是否已满 - 复制关键词并初始化计数为1 - 表长度增加 3. **`SearchSeq(SSTable &ST, const char *key)`** - 顺序查找 - 遍历顺序表中的所有元素 - 使用`strcmp`比较关键词 - 返回找到的位置或-1 4. **`CountKeywords(SSTable &ST, const char *text)`** - 统计词频 - 分词处理(按空格和标点分割) - 统一转换为小写 - 使用查找函数检查是否存在 - 存在则增加计数,不存在则插入新词 ### 时间复杂度分析: - **顺序查找**:平均时间复杂度为$O(n)$ - **词频统计**:对于包含$m$个单词的文本,时间复杂度为$O(m \times n)$ - **插入操作**:时间复杂度为$O(1)$(不考虑内存分配) ### 使用示例: ```cpp int main() { SSTable ST; InitSSTable(ST); // 统计文本词频 const char *text = "The quick brown fox jumps over the lazy dog"; CountKeywords(ST, text); // 打印结果 PrintFrequency(ST); // 查找特定词 int pos = SearchSeq(ST, "the"); if (pos != -1) { cout << "找到\"the\",出现次数: " << ST.elem[pos].count << endl; } delete[] ST.elem; return 0; } ``` 此实现满足顺序表的基本操作要求,特别适合处理小规模文本的词频统计任务。对于大规模数据,可以考虑使用哈希表或平衡二叉树来提高效率[^1]。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值