项目管理

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1013    Accepted Submission(s): 360

Problem Description
我们建造了一个大项目!这个项目有n个节点,用很多边连接起来,并且这个项目是连通的!
两个节点间可能有多条边,不过一条边的两端必然是不同的节点。
每个节点都有一个能量值。

现在我们要编写一个项目管理软件,这个软件呢有两个操作:
1.给某个项目的能量值加上一个特定值。
2.询问跟一个项目相邻的项目的能量值之和。(如果有多条边就算多次,比如a和b有2条边,那么询问a的时候b的权值算2次)。

 
Input
第一行一个整数T(1 <= T <= 3),表示测试数据的个数。
然后对于每个测试数据,第一行有两个整数n(1 <= n <= 100000)和m(1 <= m <= n + 10),分别表示点数和边数。

然后m行,每行两个数a和b,表示a和b之间有一条边。
然后一个整数Q。

然后Q行,每行第一个数cmd表示操作类型。如果cmd为0,那么接下来两个数u v表示给项目u的能量值加上v(0 <= v <= 100)。
如果cmd为1,那么接下来一个数u表示询问u相邻的项目的能量值之和。

所有点从1到n标号。

 
Output
对每个询问,输出一行表示答案。
 
Sample Input
1
3 2
1 2
1 3
6
0 1 15
0 3 4
1 1
1 3
0 2 33
1 2
 
Sample Output
4
15
15
 
Author
CLJ
 
Source
 
代码:
 #pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<vector>
using namespace std;
const int maxn=;
vector<vector<int> >arr;
//vector<int>arr[maxn];
int ans[maxn];
int n,m,i;
int main(){
int cas,a,b,q,cmd,u,v;
scanf("%d",&cas);
while(cas--){
scanf("%d%d",&n,&m);
arr.clear();
arr.resize(n+);
memset(ans,,sizeof(int)*(n+));
for(i=;i<m;i++){
scanf("%d%d",&a,&b);
arr[b].push_back(a);
arr[a].push_back(b);
}
scanf("%d",&q);
while(q--){
scanf("%d",&cmd);
if(cmd==){
scanf("%d",&u);
printf("%d\n",ans[u]);
}
else{
scanf("%d%d",&u,&v);
int len=arr[u].size();
for(i=;i<len;i++)
ans[arr[u][i]]+=v;
}
}
//for(i=1;i<=n;i++)arr[i].clear();
}
return ;
}

优化之后:

 //#pragma comment(linker,"\STACK:1024000000,1024000000");
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<vector>
using namespace std;
const int maxn=;
vector<int>arr[maxn];
int ans[maxn];
int n,m,i;
int main(){
int cas,a,b,q,cmd,u,v;
scanf("%d",&cas);
while(cas--){
scanf("%d%d",&n,&m);
memset(ans,,sizeof(int)*(n+));
for(i=;i<m;i++){
scanf("%d%d",&a,&b);
arr[b].push_back(a);
arr[a].push_back(b);
}
scanf("%d",&q);
while(q--){
scanf("%d",&cmd);
if(cmd==){
scanf("%d",&u);
printf("%d\n",ans[u]);
}
else{
scanf("%d%d",&u,&v);
int len=arr[u].size();
for(i=;i<len;i++)
ans[arr[u][i]]+=v;
}
}
//for(i=1;i<=n;i++)arr[i].clear();
}
return ;
}

HDU-----(4858)项目管理(模拟)的更多相关文章

  1. HDU 4858 项目管理(邻接表 暴力模拟)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4858 我们建造了一个大项目!这个项目有n个节点,用很多边连接起来,并且这个项目是连通的! 两个节点间可 ...

  2. hdu 4858 项目管理(vector模拟)

    # include <stdio.h> # include <algorithm> # include <string.h> # include <vecto ...

  3. hdu 4858 项目管理 图的分块

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4858 我们建造了一个大项目!这个项目有n个节点,用很多边连接起来,并且这个项目是连通的!两个节点间可能 ...

  4. HDU 4858 项目管理 分块

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4858 题解: 下面说一个插入查询时间复杂度为sqrt(m)的算法: 对每个点定义两个值:val,su ...

  5. hdu 4858 项目管理(STL集装箱)

    项目管理 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submi ...

  6. hdu 4858(简单模拟)

    项目管理 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  7. HDU - 4858 项目管理

    N个点,M条无向边.现在有Q组操作,一种是给 i号点增加能量,一种是询问 i号点相邻点的能量和(点间有多条边就算两次). 据说暴力能过,但还是用这题学习了一下 点分块 . 度数不超过 sqrt(M) ...

  8. (hdu)4858 项目管理 (vector)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4858 Problem Description 我们建造了一个大项目!这个项目有n个节点,用很多边连接起 ...

  9. hdu 4858 容器的简单模拟

    我用临接表模拟容器超时 #include<stdio.h> #include<string.h> #include<vector> using namespace ...

  10. HDOJ 4858 项目管理 ( 只是有点 莫队的分块思想在里面而已啦 )

    题目: 链接:http://acm.hdu.edu.cn/showproblem.php?pid=4858 题意: 我们建造了一个大项目!这个项目有n个节点,用很多边连接起来,并且这个项目是连通的! ...

随机推荐

  1. 【转载】教你分分钟学会用python爬虫框架Scrapy爬取心目中的女神

    原文:教你分分钟学会用python爬虫框架Scrapy爬取心目中的女神 本博文将带领你从入门到精通爬虫框架Scrapy,最终具备爬取任何网页的数据的能力.本文以校花网为例进行爬取,校花网:http:/ ...

  2. Creating, Stopping, Re-Starting and Deleting a Timer in Oracle Forms

    I have written many posts previously on Timers in Oracle Forms like how to change images randomly wi ...

  3. python 中类方法@classmethod

    classmethod是用来指定一个类的方法为类方法,没有此参数指定的类的方法为实例方法,使用方法如下: class C: @classmethod def f(cls, arg1, arg2, .. ...

  4. Spring的起源和背景

    上图为Spring框架的组成结构 下面这几张也是的 Spring将大量实际开发中需要重复解决的步骤,抽象成了一个框架. 其中Spring Core Container是Spring框架的核心机制. S ...

  5. 6.Type and Member Basics

    1.The Different Kinds of Type Members 1.Constants:a symbol that identifies a never-changing data val ...

  6. [Effective Java]第六章 枚举和注解

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

  7. zoj 2107&&hdu 1007最近点对问题

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1107 Quoit Design Time Limit: 5 Seconds   ...

  8. django(一)搭建开发环境

    本学习系列均使用centos7操作系统,基于python3进行操作.centos7下的python3安装配置http://www.cnblogs.com/Guido-admirers/p/625941 ...

  9. STORM_0002_在做好的zookeeper集群上搭建storm的开发环境

    参考文献http://www.cnblogs.com/panfeng412/archive/2012/11/30/how-to-install-and-deploy-storm-cluster.htm ...

  10. 访问Google搜索,Google学术镜像搜索

    Google学术镜像搜索:http://dir.scmor.com/google/ 不用FQ也能访问谷歌搜索网站,让我们一起Google 不用FQ也能访问谷歌搜索网站,让我们一起Google(摘自:h ...