您的位置:首页 > 其它

项目管理 hdoj 4858 (vector初学)

2016-04-29 20:16 399 查看
项目管理 hdoj 4858 (vector初学)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4858

本身是个水水题,但是给刚学的朋友练练手是可以的咯。

题目因为数据太大,会爆内存,用时间换内存就爆了时间。。。

看了下题解,知道用vector,就把vector学了下,水了下面的题。

还不会的同学快来看看吧:

/article/8247661.html

ac代码

注意:用cin,cout会爆时间。。。

#include <stdio.h>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
#define N 100001
#define PI 3.1415927
vector<int> a
;
int sum
;
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
memset(a,0,sizeof(a));
memset(sum,0,sizeof(sum));
int m,n;
scanf("%d%d",&n,&m);
while(m--)
{
int x,y;
scanf("%d%d",&x,&y);
a[x].push_back(y);
a[y].push_back(x);
}
int h;
scanf("%d",&h);
while(h--)
{
int pan;
cin >> pan;
if(pan)
{
int x,ans=0;
scanf("%d",&x);
for(int i = 0; i < a[x].size(); i++)
ans += sum[a[x][i]];
printf("%d\n",ans);
}
else
{
int x,y;
scanf("%d%d",&x,&y);
sum[x] += y;
}
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: