Cpp

154【杂项】算竞常用_C++_STL_用法

C++ 标准模板库 (STL, Standard Template Library):包含一些常用数据结构与算法的模板的 C++ 软件库。其包含四个组件——算法 (Algorithms)、容器 (Containers)、仿函数 (Functors)、迭代器 (Iterators).

示例:

  • 算法:sort(a.begin(), a.end())
  • 容器:priority_queue<int> pque
  • 仿函数:greater<int>()
  • 迭代器:vector<int>::iterator it = a.begin()

1 前言 #

STL 作为一个封装良好,性能合格的 C++ 标准库,在算法竞赛中运用极其常见。灵活且正确使用 STL 可以节省非常多解题时间,这一点不仅是由于可以直接调用,还是因为它封装良好,可以让代码的可读性变高,解题思路更清晰,调试过程 往往 更顺利。

不过 STL 毕竟使用了很多复杂的结构来实现丰富的功能,它的效率往往是比不上自己手搓针对特定题目的数据结构与算法的。因此,STL 的使用相当于使用更长的运行时间换取更高的编程效率。因此,在实际比赛中要权衡 STL 的利弊,不过这一点就得靠经验了。

接下来,我会分享在算法竞赛中常用的 STL 容器和算法,对于函数和迭代器,就不着重展开讲了。

2 常用容器 #

2.1 内容总览 #

打勾的是本次将会详细讲解的,加粗的是算法竞赛中有必要学习的。

  • 顺序容器

    • array

    • vector

    • deque

    • forward_list

    • list

  • 关联容器

    • set
    • map
    • multiset
    • multimap
  • 无序关联容器

    ...

qt学习

建议版本 #

  • Qt 4.8.7 官方推荐的 MinGW 版本为 4.4.x,但是MinGW4.4没法编译,MinGW4.5才行,然后找不到MinGW4.5,这里使用了MinGW4.8。qtCreator配套推荐3.0.1(也可以用3.5.0)

下载(视频所用版本) #

- perl-->  https://strawberryperl.com/download/5.16.3.1/strawberry-perl-5.16.3.1-32bit-portable.zip
- MinGW(4.8.1): https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win32/Personal%20Builds/mingw-builds/4.8.1/threads-posix/sjlj/i686-4.8.1-release-posix-sjlj-rt_v3-rev2.7z/download (兼容windowsXP)
- (推荐)https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win32/Personal%20Builds/mingw-builds/4.8.2/threads-posix/dwarf/ (新版win7以上)
=====qt 4.8.7========
- qt库(带MinGW和qtCreator) :https://download.qt.io/new_archive/qt/4.8/4.8.7/qt-opensource-windows-x86-mingw482-4.8.7.exe
- qt库(源码): https://download.qt.io/new_archive/qt/4.8/4.8.7/qt-everywhere-opensource-src-4.8.7.zip
- qtCreator: https://qt.mirror.constant.com/archive/qtcreator/3.0/3.0.1/qt-creator-opensource-windows-x86-3.0.1.exe
===弃用===
- MinGW(4.4): https://www.123912.com/s/u5pSjv-32uAH?提取码:M27Z  
	- 要记得设置环境变量
- qt库: https://download.qt.io/archive/qt/4.7/qt-win-opensource-4.7.0-mingw.exe  
- Qt Creator: https://download.qt.io/archive/qtcreator/2.0/qt-creator-win-opensource-2.0.1.exe  
====使用5.0.2====
qt+mingw--> https://download.qt.io/archive/qt/5.0/5.0.2/qt-windows-opensource-5.0.2-mingw47_32-x86-offline.exe
源码-->  https://download.qt.io/archive/qt/5.0/5.0.2/single/qt-everywhere-opensource-src-5.0.2.zip
=====在线版5.15======
https://mirrors.tuna.tsinghua.edu.cn/qt/official_releases/online_installers/qt-online-installer-windows-x64-online.exe
- .\qt-online-installer-windows-x64-online.exe  --mirror https://mirrors.ustc.edu.cn/qtproject 
- Archive中选择5.15及6.8
- 安装内容:MinGW,Android,QtCharts,QtMultimedia,QtQuich3D,QtShaderTools
=====其他=======
- qt库(带MinGW和qtCreator): https://download.qt.io/new_archive/qt/5.2/5.2.1/qt-opensource-windows-x86-mingw48_opengl-5.2.1.exe

编译静态编译的qmake #

  • 下载源码
  • 路径不能有奇奇怪怪的符号(.-_ 之类)
  • (弃)修改 E:\Qt\qtSrc\qtbase\mkspecs\win32-g++\qmake.conf,修改QMAKE_LFLAGS = -static -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc(仅添加-static)

目录结构 #

#mkdir "E:\Qt\qtCustom487\buildQtStatic" #/p
mkdir "E:\Qt\qtCustom\buildQtStatic" #/p
#mkdir "E:\Qt\qtCustom487\qtStatic" #/p
mkdir "E:\Qt\qtCustom\qtStatic" 
#mkdir "E:\Qt\qtCustom487\qtSrc" #/p
mkdir "E:\Qt\qtCustom\qtSrc"  
#E:\Qt\qtCustom下
				- buildQtStatic #(新建的)编译时切换到这个目录
				- qtSrc #源码
				- qtStatic #(新建的)install目录

静态编译 #

我用的是视频0087集的办法,也可以用 https://www.cnblogs.com/atggg/p/16878575.html试试

...