Her_Lingxiao @ 2020-06-08 11:54:16
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
int main()
{
int n, q;
int ZanCun[5];
vector<vector<int> > Cab;
scanf("%d %d", &n, &q);
#if 0
printf("\n%d %d\n", n, q);
#endif
for(int i = 1; i <= q; i++)
{
memset(ZanCun, 0, 5);
int a;
scanf("%d", &a);
if(a == 1)
{
for(int j = 1; j <= 3; j++)
scanf("%d", &ZanCun[j]);
if(ZanCun[3] != 0)
Cab[ZanCun[1]][ZanCun[2]] += ZanCun[3];
else
Cab[ZanCun[1]][ZanCun[2]] = 0;
}
else if(a == 2)
{
for(int j = 1; j <= 2; j++)
scanf("%d", &ZanCun[j]);
printf("%d\n", Cab[ZanCun[1]][ZanCun[2]]);
}
}
return 0;
}
by C6H14 @ 2020-06-08 13:02:43
Cab要初始化
by 从蒟蒻到小犇 @ 2020-06-08 14:48:38
vector得用push_back操作的……建议楼主学到图论的时候再磕vector吧,这个STL用法难度不是入门水平感觉……
by shiroi @ 2020-06-08 15:40:40
有语法错误。这样使用需要resize
by Her_Lingxiao @ 2020-06-10 14:48:41
我又改了一下,但是只有20分……
#include <cstdio>
#include <iostream>
#include <cstring>
#include <vector>
using namespace std;
const int MAX = int(1e5) + 20;
struct BigCub
{
vector<int> NumCub;
vector<int> ThingCub;
}cub[MAX];
int temp;
int main()
{
int n, q;
scanf("%d %d", &n, &q);
for(int i = 1; i <= q; i++)
{
int Judge;
scanf("%d", &Judge);
if(Judge == 1)
{
int x, y, num;
scanf("%d %d %d", &x, &y, &num);
cub[x].NumCub.push_back(y);
cub[x].ThingCub.push_back(num);
}
if(Judge == 2)
{
int x, y;
scanf("%d %d", &x, &y);
for(int j = 0; j < cub[x].NumCub.size(); j++)
{
if(cub[x].NumCub[j] == y)
{
cout << cub[x].ThingCub[j] << endl;
break;
}
}
}
}
return 0;
}
by Her_Lingxiao @ 2022-07-07 00:07:28
没事了
两年了 过了()