第三章 STL和基本数据结构
3.1 容器
1.顺序式容器
2.关联式容器
3.1.1 vector
1.定义
vectora; 默认初始化,a为空
vectorb(A); 用A定义b
vectora(n); a有n个值为0的元素
vectora(a,n); a个值为n的元素
vectora(10,"null"); 10个值为null的元素
vectorvec(10,"hello"); 10个值为hello的元素
vectorb(a.begin(),a.end()); b是a的复制
struct point{int x,y;}; vectora; a用来存坐标
##多维数组 vectora[MAXN];
2.常用操作
a.push_back(n); 在尾部添加元素n
int size=a.size(); 查询元素个数
bool isEmpty=a.empty(); 判断是否为空
cout<
例题
hdu 4841
http://acm.hdu.edu.cn/showproblem.php?pid=4841
#include
#include
#include
using namespace std;
vectortable;
int n,m;
int main()
{
while(cin>>n>>m)
{
table.clear();
for(int i=0;i<2*n;i++) table.push_back(i);
int pos=0;
for(int i=0;i