C++ 使用 map 容器时,索引应该使用 pair 类型作为键
{"title":"C++ 使用 map 容器时,索引应该使用 pair 类型作为键","description":"本文介绍了在 C++ 中使用 map 容器时,索引应该使用 pair 类型作为键,而不是使用逗号分隔的两个值。并给出了示例代码。","keywords":"C++, map, pair, 索引, 容器, 优先队列, operator<, 错误修复, 代码示例","content":"struct node{\n\tdouble G,H,f;\n};\nmap<pair<double,double>,node> mp;\nstruct data{\n\tdouble x,y;\n};\npriority_queue q;\nbool operator<(const data &a,const data &b){\n\treturn mp[make_pair(a.x,a.y)].G+mp[make_pair(a.x,a.y)].H>mp[make_pair(b.x,b.y)].G+mp[make_pair(b.x,b.y)].H;//从小到大排序\n}\n"}
原文地址: https://www.cveoy.top/t/topic/p92L 著作权归作者所有。请勿转载和采集!