c++ STL map 结构体

杂记1:正向反向迭代器,不同stl容器的lower_bound的使用(set,map,vector,arr,pair),数字转字符串 感觉自己记性真的不行,很多之前用过,查过的知识点都忘掉了,开个博客记一下吧。 文章目录迭代器lower_bound,upper_bound可以忽略,我暂时没发现用处这个比较有用:不同容器的lower_boundpair+lower_bound 迭代器 基本格式: 容器类名::iterator 迭代器名; 举两个例子 vector<int>::iterator ite; map<int,int>::iterator ite; 迭代器又分四种,常用的是正向迭代器(上面那个)和反 阅读详情

点击打开链接

点击打开链接

Map是STL的一个关联容器,它提供一对一(其中第一个可以称为关键字,每个关键字只能在map中出现一次,第二个可能称为该关键字的值)的数据处理能力,由于这个特性,它完成有可能在我们处理一对一数据的时候,在编程上提供快速通道。这里说下map内部数据的组织,map内部自建一颗红黑树(一种非严格意义上的平衡二叉树),这颗树具有对数据自动排序的功能,所以在map内部所有的数据都是有序的,后边我们会见识到有序的好处。

在一些特殊情况,比如关键字是一个结构体,涉及到排序就会出现问题,因为它没有小于号操作,insert等函数在编译的时候过不去,下面给出两个方法解决这个问题

第一种:小于号重载,程序举例

#include <map>

#include <string>

Using namespace std;

Typedef struct tagStudentInfo

{

       Int      nID;

       String   strName;

}StudentInfo, *PStudentInfo;  //学生信息

 

Int main()

{

    int nSize;

       //用学生信息映射分数

       map<StudentInfo, int>mapStudent;

    map<StudentInfo, int>::iterator iter;

       StudentInfo studentInfo;

       studentInfo.nID = 1;

       studentInfo.strName = “student_one”;

       mapStudent.insert(pair<StudentInfo, int>(studentInfo, 90));

       studentInfo.nID = 2;

       studentInfo.strName = “student_two”;

mapStudent.insert(pair<StudentInfo, int>(studentInfo, 80));

 

for (iter=mapStudent.begin(); iter!=mapStudent.end(); iter++)

    cout<<iter->first.nID<<endl<<iter->first.strName<<endl<<iter->second<<endl;

 

}

以上程序是无法编译通过的,只要重载小于号,就OK了,如下:

Typedef struct tagStudentInfo

{

       Int      nID;

       String   strName;

       Bool operator < (tagStudentInfo const& _A) const

       {

              //这个函数指定排序策略,按nID排序,如果nID相等的话,按strName排序

              If(nID < _A.nID)  return true;

              If(nID == _A.nID) return strName.compare(_A.strName) < 0;

              Return false;

       }

}StudentInfo, *PStudentInfo;  //学生信息

第二种:仿函数的应用,这个时候结构体中没有直接的小于号重载,程序说明

#include <map>

#include <string>

Using namespace std;

Typedef struct tagStudentInfo

{

       Int      nID;

       String   strName;

}StudentInfo, *PStudentInfo;  //学生信息

 

Classs sort

{

       Public:

       Bool operator() (StudentInfo const &_A, StudentInfo const &_B) const

       {

              If(_A.nID < _B.nID) return true;

              If(_A.nID == _B.nID) return _A.strName.compare(_B.strName) < 0;

              Return false;

       }

};

 

Int main()

{

       //用学生信息映射分数

       Map<StudentInfo, int, sort>mapStudent;

       StudentInfo studentInfo;

       studentInfo.nID = 1;

       studentInfo.strName = “student_one”;

       mapStudent.insert(pair<StudentInfo, int>(studentInfo, 90));

       studentInfo.nID = 2;

       studentInfo.strName = “student_two”;

mapStudent.insert(pair<StudentInfo, int>(studentInfo, 80));

}

  1. /****************************************************************** 
  2.       map的基本操作函数: 
  3.       C++ Maps是一种关联式容器,包含“关键字/值”对 
  4.       begin()          返回指向map头部的迭代器 
  5.       clear()         删除所有元素 
  6.       count()          返回指定元素出现的次数 
  7.       empty()          如果map为空则返回true 
  8.       end()            返回指向map末尾的迭代器 
  9.       equal_range()    返回特殊条目的迭代器对 
  10.       erase()          删除一个元素 
  11.       find()           查找一个元素 
  12.       get_allocator()  返回map的配置器 
  13.       insert()         插入元素 
  14.       key_comp()       返回比较元素key的函数 
  15.       lower_bound()    返回键值>=给定元素的第一个位置 
  16.       max_size()       返回可以容纳的最大元素个数 
  17.       rbegin()         返回一个指向map尾部的逆向迭代器 
  18.       rend()           返回一个指向map头部的逆向迭代器 
  19.       size()           返回map中元素的个数 
  20.       swap()            交换两个map 
  21.       upper_bound()     返回键值>给定元素的第一个位置 
  22.       value_comp()      返回比较元素value的函数
  1. ==================================================================== 
  2. 1、map构造 
  3.     map<int, string> mapStudent; 
  4.  
  5. 2、map添加数据 
  6.     mapStudent.insert(pair<int, string>(1, "student_one")); 
  7.     mapStudent.insert(map<int, string>::value_type(2, "student_two")); 
  8.     mapStudent[3] = "student_three"; 
  9.  
  10. ********************************************************************/  
  11. #pragma warning (disable:4786)  
  12. #include <map>  
  13. #include <string>  
  14. #include <iostream>  
  15.   
  16. using namespace std;  
  17.   
  18. int main()  
  19. {  
  20.     map<int, string> mapStudent;  
  21.     cout<<"三种插入方式:"<<endl;  
  22.   
  23.     mapStudent.insert(pair<int, string>(1, "student_one"));  
  24.     mapStudent.insert(map<int, string>::value_type(2, "student_two"));  
  25.     mapStudent[3] = "student_three";  
  26.     mapStudent.insert(map<int, string>::value_type(4, "student_four"));     
  27.       
  28.     pair<map<int,string>::iterator,bool> InsertPair;   //判断是否插入成功  
  29.     InsertPair = mapStudent.insert(map<int,string>::value_type(5,"student_five"));  
  30.     if(InsertPair.second == true)  
  31.     {  
  32.         //cout<<InsertPair.first.operator++<<endl;  //求解??不知道怎么应用第一个数据  
  33.     }  
  34.   
  35.     cout<<"三种遍历方式:"<<endl;  
  36.   
  37.     map<int, string>::iterator  iter;  
  38.     for(iter = mapStudent.begin(); iter != mapStudent.end(); iter++)  
  39.     {  
  40.         cout<<iter->first<<" "<<iter->second<<endl;  
  41.     }  
  42.   
  43.     map<int, string>::reverse_iterator  iters;  
  44.     for(iters = mapStudent.rbegin(); iters != mapStudent.rend(); iters++)  
  45.     {  
  46.         cout<<iters->first<<" "<<iters->second<<endl;  
  47.     }  //逆序输出  
  48.     cout<<"数组的输出形式:"<<endl;  
  49.     for(int iIndex=0;iIndex < mapStudent.size();iIndex++) //size()返回成员的个数  
  50.     {  
  51.         cout<<mapStudent[iIndex]<<endl;  
  52.     }  
  53.     cout<<mapStudent.count(1)<<endl;  //count()判断关键字是否存在,返回1表示存在,0  
  54.     iter = mapStudent.find(1);        //find()关键字存在时,返回数据所在位置的迭代器,否则返回end()返回的迭代器  
  55.     if( iter != mapStudent.end() )  
  56.     {  
  57.         cout<<"数据存在:"<<iter->first<<" "<<iter->second<<endl;  
  58.         mapStudent.erase(iter);        //用迭代删除数据  
  59.     }  
  60.     else  
  61.     {  
  62.         cout<<"数据不存在!"<<endl;  
  63.     }  
  64.     int n = mapStudent.erase(3);        //用关键字删除,如果删除了会返回1,否则返回0  
  65.   
  66.     iter = mapStudent.lower_bound(2);   //返回2的迭代器  
  67.     cout<<iter->second<<endl;  
  68.     iter = mapStudent.upper_bound(2);   //返回3的迭代器  
  69.     cout<<iter->second<<endl;      
  70.   
  71.     /*Equal_range函数返回一个pair,pair里面第一个变量是Lower_bound返回的迭代器,pair里面第二个迭代器是Upper_bound返回的迭代器,如果这两个迭代器相等的话,则说明map中不出现这个关键字*/  
  72.     pair<map<int,string>::iterator,map<int,string>::iterator> MapPair;  
  73.     MapPair = mapStudent.equal_range(2);  
  74.     if( MapPair.first == MapPair.second )  
  75.     {  
  76.         cout<<"Do not find"<<endl;  
  77.     }  
  78.     else  
  79.     {  
  80.         cout<<"Find"<<endl;  
  81.     }  
  82.   
  83.     //删除一个前闭后开的集合,这是STL的特性  
  84.     mapStudent.earse(mapStudent.begin(), mapStudent.end());      
  85. }

C++ map以自定义数据类型做键值 前言 作者最近在项目开发中遇到一个问题,想采用自定义的结构体作为键值,但是无论怎样,就连编译都不能通过,针对这个问题,作者就开始寻求解决的办法.。终于这个问题得以解决,高兴之余,决定写个例子,供大家参考 1.map在STL中的定义 template, class A = allocator > 第一个参数 Key: map的关键字类型 第二个参数T:      map的值类型 第 阅读详情

相关推荐

C++中的map可以使用结构体作为键值吗?

在上面的代码中,我们定义了一个Person结构体,其中有两个成员变量name和age。然后,我们定义了一个map对象persons,它的键值类型是Person,值类型是int。需要注意的是,在使用结构体作为键值时,需要实现小于号运算符(operator

James_CODER的博客 827

c++ map中key为结构体

map中key为结构体 项目中需要将结构体作为hash的key,一开始用hash_map,但是结构体中多值比较一直失败,所以尝试了map。 hash_map 查找速度会比map快,而且查找速度基本和数据量大小无关,属于常数级别;而map的查找速度是log(n)级别。hash还有hash函数的耗时。当有100w条记录的时候,map也只需要20次的比较,200w也只需要21次的比较!所以并不一定常数就比log(n) 小。 hash_map对空间的要求要比map高很多,所以是以空间换时间的方法,而且,hash_m

qq_34462436的博客 3558

基于YOLO11深度学习的糖尿病视网膜病变智能诊断系统【Python源码+Pyqt5界面+数据集+训练代码】

本文详细介绍如何利用YOLO11深度学习技术构建糖尿病视网膜病变智能诊断系统。项目提供完整的Python源码、PyQt5图形界面、标注数据集及训练代码,实现从图片、视频到摄像头的多模态病变检测,旨在辅助医疗筛查,提升诊断效率。

weixin_29089057的博客 280

C++字符串切分: split实现

std::vector split(const std::string& s, const std::string& delim) { std::vector elems; size_t pos = 0; size_t len = s.length(); size_t delim_len = delim.length(); if (delim_len ==

yangalbert的专栏 9692

新手必看:瑞萨MCU选型时,QFP、QFN、BGA这些封装到底该怎么选?(附选型避坑指南)

本文详细解析了瑞萨MCU选型中QFP、QFN、BGA等封装的特点与适用场景,提供实战避坑指南。通过对比封装的空间占用、散热能力、焊接难度等核心维度,帮助工程师根据具体需求选择最合适的芯片封装,避免因选型不当导致的高成本与生产问题。

weixin_26965807的博客 424

贴片二极管SOD封装详解:SOD-123/323/523尺寸焊盘设计要点

表面贴装技术中,二极管封装尺寸直接决定PCB布局与焊接可靠性。SOD封装作为小外形二极管的主流形态,其SOD-123、SOD-323、SOD-523三种规格分别对应不同的功耗与占板面积权衡。理解封装尺寸、焊盘设计计算逻辑和钢网开窗原理,是避免立碑、虚焊等工艺缺陷的关键。在可穿戴设备、电源保护等空间受限场景中,合理选择封装不仅能优化散热路径,还能提升量产良率。本文从焊盘计算、工艺要点到选型策略,全面解析SOD封装的工程实践。

weixin_42520780的博客 341

c++ map容器的key为结构体时如何找key

当key为结构体时,直接用find(key),或者map.value(key)会报错。就可以正常使用find和value了。

qq_43940235的博客 455

channel || channelGroup || ctx.writeAndFlush()发送字符串消息客户端接收不到的原因

一、原因 网络上传播的数据都是字节(二进制数据)类型。我们如果直接向网络流里面写入一个对象(如:String对象),是无法传输的。只有将对象序列化(转换为可以传输的字节类型)之后,才可以进行传输。所以问题的根源就很清楚了,需要把字符串转换成字节进行传输。、 二、解决办法 1、手动序列化 服务端: channelGroup.writeAndFlush(Unpooled.copiedBuffer("【客户端】"+remoteAddress+"已下线"+format.format(new Date()), Cha

haohaoxuexiyai的博客 4065

C++ 数组、指针、数组指针、指针数组、多级指针、STL-map、结构体 的 初始化 及其 初始化赋值

它表示一个包含10个元素的【数组a】,每个【元素】都是指向int类型数据的【指针】。想要让【数组】存储【指向 int 或 char 或其他数据类型的指针】想要让【数组】存储【指向 int 或 char 或其他数据类型的指针】new int [m][n] 连续分配m。第二行代码:int (*a)[10];[m] 分散的int*数组,一共m个。从右至左,表示先算右边,再算左边。第一行代码:int* a[10];一个包含10个整数的int类型数组。[]优先级最高,先 a[]

zsssss333的博客 974

微信小程序 - 最新详细实现跳转打开第三方网站方法流程及示例代码,在小程序内直接打开H5页面或微信公众号文章后台业务域名配置及下载校验文件上传服务器,嵌入外部网站跳转第三方h5网页(详细配置及代码)

微信小程序,打开第三方网站,放校验文件,怎么配置业务域名,后台配置,怎么打开外部没有关联的网站,小程序直接打开公众号文章,指定页面,跳转第三方url,跳转到外部网站,小程序跳转到任意外部网页,网站链接,跳转到其他网页(外部链接),小程序嵌入外部h5链接,校验文件怎么放到对方服务器上,要跳转到网站没权限放过去,校验文件验证域名,把校验文件放到对面网站,别人的服务器也打不开没权限怎么放呢,勾选不校验合法域名,txt,打不开别人的网页怎么办,真机调试打不开,无法跳转,有什么其他办法不放校验文件吗,别人不可能同意,

🏆 前端领域优质创作者 1万+

技术面 - 手撕算法题整理

这篇博客整理了华为OD面试中涉及的算法题,包括LeetCode热门题目、OD原题和需要手写的算法,如二分查找、冒泡排序等。建议优先刷"hot100"的LeetCode题目,全刷OD原题,以及掌握手撕算法的基本原理。

m0_73659489的博客 1029

C++ STL 结构体作为map的键

在使用map等关联式容器时,用结构体作为键时,在用到键比较的场合时会报错,键无法比较。 比如: map每次插入新元素都需要比较键,自动排序。 map.count(key)对某一键计数。 因为键是我们自定义的,编译器找不到类似模板,无法比较。我们自己重载<运算符即可,指出我们在比较结构体时具体是比较哪个成员变量。 struct Test{ string data; int x; bool operator<(const package& tmp) con

LOG_IN_ME的博客 913

1 四种防反接电路——multisim仿真

摘要:防反接电路可防止电源反接损坏器件,主要有四种方案:1)二极管串联(低成本,适用小电流);2)整流桥(无极性输入,但效率低);3)保险丝+稳压管(低损耗但需更换);4)MOS管方案(大电流、高效率,主流选择)。选型需考虑电流、压降和成本,MOS管因其低导通电阻(毫欧级)成为大电流应用的首选。口诀:"小电流二极管,大电流用MOS"可快速指导设计。

XU157303764的博客 1585

C++中stl容器map针对结构体的查找

#include #include #include #include using namespace std; typedef struct MAPDATA { char data[128]; //map中数据 bool operator {  return a.data } }MAPDATA; int main() { map mp; stru

Never too late to study 2281

基于YOLOv8深度学习的火焰与烟雾检测系统详解:UI界面 + YOLOv8 + 数据集的实现

通过自动化检测火焰和烟雾,可以提高响应速度,减少潜在的火灾损失,保障人身和财产安全。此外,应用还会显示标记了检测框的视频画面,方便用户直观了解检测效果。同时,前端界面将使用Streamlit来实现,因其可以快速搭建交互式应用,适合我们的需求。要训练一个有效的火焰和烟雾检测模型,我们需要一个包含火焰和烟雾图片的数据集。为了保证模型的准确性和泛化能力,建议收集至少500张火焰和烟雾的图片,保证数据的多样性和代表性。训练过程中,模型会输出每个Epoch的训练损失和验证准确率,便于我们监控模型的学习情况。

YOLO 1322

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

天梯赛L2口罩发放题:如何用C++ STL模拟复杂业务逻辑(map、vector、结构体实战)

本文详细解析了团体程序设计天梯赛L2口罩发放题的C++实现方法,重点介绍了如何利用STL容器(map、vector)和结构体模拟复杂业务逻辑。通过身份证验证、冷却期检查和多条件排序等实战示例,帮助开发者掌握算法竞赛中的工程化编码技巧,提升数据处理和业务模拟能力。

weixin_30566111的博客 418

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

C++-STL(11)-map-结构体指针作为key

map中如果要存的是结构体指针怎么做?创建时:要重载 <函数,你得告诉Map如何排序。查找时:重载==,你得告诉MAP何时相等。删除时:delete外还要置空,因为是new的。 上代码: #include <map> #include <iostream> using namespace std; struct Key { int x, y; boo...

aggie4628的专栏 1447

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

map结构体作为key值的使用

最近在使用stl中的map容器时,碰到key为结构体的情况,总结如下,以便提醒自己。 因为之前从没用结构体作为key值,也就没出现这种情况,结果报错后很崩溃看不懂 后来才知道map中的key默认是以less 所以要对结构体中 然后就可以使用了

codeswarrior的博客 5260

网易博客旧文--STL中如何在map中使用结构体作为索引

这里的关键其实就是定义结构时需要重载

XZHOUMIN的博客 474

C++ STL map key是自定义结构体或类

/// @file 1.cpp /// @brief /// @author EastonWoo /// 0.01 /// @date 2015-11-02 #include #include #include #include #include #include class CKey{ public: CKey(std::string str1, std::stri

EastonWoo的专栏 9526

STL map中key为结构体的用法

最近在使用stl中的map容器时,碰到key为结构体的情况,总结如下,以便提醒自己。 我的使用情景是,我需要根据不同的比例尺、道路类型这两个参数获取到对应的道路宽度,由于我是使用map解决这个问题的, 自然而然的就以比例尺、道路类型这两个参数为key,道路宽度为value,建立的key如下: 1 typedef struct tagRoadKey  2 { 3     int nTy

Mrknowledge 1125
上一篇: c++ map<string,string>
下一篇: 最短路径算法—Dijkstra(迪杰斯特拉)算法分析与实现(C/C++)
Lemoneasy
博客等级 码龄17年 11粉丝 15原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值