目录

蓝桥杯备考数据结构vector篇之寄包柜

目录

蓝桥杯备考:数据结构vector篇之寄包柜

https://i-blog.csdnimg.cn/direct/52d7149734bf4873bf560419992d4351.png https://i-blog.csdnimg.cn/direct/f838f801195f4e4093c7cb289f901130.png 这道题,每个柜子都有很多个格子,但是具体多少格子是不确定的,我们知道的是格子的总数一共不超过10的7次方 这道题,如果我们用数组的话,10的五次方乘10的五次方是一定会超时的 所以我们只能用vector来解决这道问题,一共才会开不到10的7次方个格子 #include #include using namespace std; const int N = 1e5+10; //int a[N][N]//空间太大,程序运行不了 vector a[N];//正确√ int n,q; int main() { cin » n » q; while(q–) { int op,i,j;cin » op » i » j; if(op == 1) { int x;cin » x; if(a[i].size() < j) { a[i].resize(j+1); } a[i][j] = x; } else if(op == 2) { cout « a[i][j] « endl; } } return 0; }