1、map<int,vector >m;
直接将每一个元素当作一个vector 非常方便;
m[t1].push_back(t2);
m[t2].push_back(t1);
1090 危险的集装箱
#include
#include
cin>>n>>m;
map<int,vector >v;
while(n–)
{
int x,y;
cin>>x>>y;
v[x].push_back(y);
v[y].push_back(x);
}
m1=m;
while(m–)
{
int z,flag=0,a[100000]={0},q,p;
cin>>z;
vectorw;
while(z–)
{
cin>>q;
w.push_back(q);
a[q]=1;
}
for(int j=0;j<w.size();j++)
{
for(int q=0;q<v[w[j]].size();q++)
{
if(a[v[w[j]][q]]==1){flag=1;}
}
}
printf("%s\n",flag ? “No” :“Yes”);
}
}
2、
map<string,int> m;
map<string,int>::iterator it;
it = m.begin();
while(it != m.end())
{//it->first;
//it->second;
it ++;
}
3、
map<int, string>::iterator iter;
for(iter = mapStudent.begin(); iter != mapStudent.end(); iter++)
cout<first<<’ '<second<<endl;