BestCoder Round #1 第二题 项目管理

// 第二题 我记得很久很久很久以前看过这样的题目,忘记是哪的区域赛了

// 记得有人说和节点度数有关,我记不清了,反正当时完全不懂

// 然后我想了想,估计就是更新节点度数有关,YY出来可能只要更新相邻节点度数更大或更小的就可以了

// 复杂度不知道多少,就是提交了试试,15MS就过了

// 看来就是这样了

// 具体就是求出每个节点度数,然后每次更新时,只要更新与自己相连,但度数比自己大的

// 查询时把度数自己大的节点累加的值加上就可输出,具体看代码比较清楚

// 也就做得来这2题了(见识少,以前题目做得少)。

// 不过在厦门实训感觉蛮悠闲,企业上课就是比学校效率

#include <iostream>
#include <string.h>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
using namespace std;
#define LL long long
#define N 100010
#define mod 1000000007
vector<int> V[N],up[N];//V记录边,up记录邻接节点,但度数自己大
int in[N];//记录节点度数
int sum[N],add[N];//add 保存更新
int main()
{
  //  priority_queue<int,vector<int>,greater<int> >
    int T;
    int n,m,Q;
    int a,b;
    int i,j;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d %d",&n,&m);
        for(i=1;i<=n;i++){
            V[i].clear();
            in[i]=0;
            up[i].clear();
            sum[i]=add[i]=0;
        }
        while(m--)
        {
           scanf("%d %d",&a,&b);
           V[a].push_back(b);
           V[b].push_back(a);
           in[b]++;
           in[a]++;
        }

        for(a=1;a<=n;a++)
            for(j=0;j<V[a].size();j++)
         {
             b=V[a][j];
            if(in[b]>=in[a])
                up[a].push_back(b);
         }
       scanf("%d",&Q);
       int cmd,u,v;
       while(Q--)
       {
           scanf("%d %d",&cmd,&u);
            if(cmd==0)
            {
                scanf("%d",&v);
                add[u]+=v;
                for(i=0; i<up[u].size(); i++)
                {
                    j=up[u][i];
                    sum[j]+=v;
                }
            }
            else
            {
                int ans=sum[u];
               for(i=0; i<up[u].size(); i++)
                {
                    j=up[u][i];
                    if(in[j]!=in[u])
                     ans+=add[j];
                }
                printf("%d\n",ans);
            }
       }

    }
    return 0;
}

BestCoder Round #1 第二题 项目管理

时间: 2024-08-28 09:12:03

BestCoder Round #1 第二题 项目管理的相关文章

hdu4931 Happy Three Friends(BestCoder Round#4签到题)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4931 Happy Three Friends Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 150    Accepted Submission(s): 128 Problem Description Dong-hao , Grandpa

BestCoder Round #1 第一题 逃生

// 等了好久,BESTCODER 终于出来了..像咋这样的毕业的人..就是去凑凑热闹// 弱校搞acm真是难,不过还是怪自己不够努力// 第一题是明显的拓扑排序,加了了个字典序限制而已// 用优先队列就可以搞定了#include <iostream> #include <string.h> #include <stdio.h> #include <algorithm> #include <vector> #include <map>

ACM学习历程—HDU5269 ZYB loves Xor I(位运算 &amp;&amp; dfs &amp;&amp; 排序)(BestCoder Round #44 1002题)

Problem Description Memphis loves xor very musch.Now he gets an array A.The length of A is n.Now he wants to know the sum of all (lowbit(Ai xor Aj) (i,j∈[1,n]) We define that lowbit(x)=2^k,k is the smallest integer satisfied ((x and 2^k)>0)Specially,

BestCoder Round #31 B题

beautiful number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 136    Accepted Submission(s): 78 Problem Description Let A=∑ni=1ai?10n?i(1≤ai≤9)(n is the number of A's digits). We call A as "

BestCoder Round #14 B 题 Harry And Dig Machine 【TSP】

题目:Harry And Dig Machine 哈哈  终于涨边粉色了,不容易呀.顺便写一道题解吧 题意:给一个m*n的矩阵,然后其中最多由10个有值,求总左上角把所有的值都拿上回到左上角的最小步数. 标准的TSP回到原点问题,需要先预处理出图来,然后TSP即可. AC代码: #include <cstdio> #include <algorithm> #include <cstring> #include <string> #include <io

从lca到树链剖分 bestcoder round#45 1003

bestcoder round#45 1003 题,给定两个点,要我们求这两个点的树上路径所经过的点的权值是否出现过奇数次.如果是一般人,那么就是用lca求树上路径,然后判断是否出现过奇数次(用异或),高手就不这么做了,直接树链剖分.为什么不能用lca,因为如果有树退化成链,那么每次询问的复杂度是O(n), 那么q次询问的时间复杂度是O(qn) 什么是树链剖分呢? 就是把树的边分成轻链和重链 http://blogsina.com.cn/s/blog_6974c8b20100zc61.htmlh

HDU-5086-Revenge of Segment Tree (BestCoder Round #16)

Revenge of Segment Tree Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 205    Accepted Submission(s): 83 Problem Description In computer science, a segment tree is a tree data structure for st

BestCoder Round #4 前两题 hdu 4931 4932

第一题太水了.. 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 using namespace std; 6 int a[6]; 7 int main(){ 8 int cas; 9 scanf( "%d", &cas ); 10 while( cas-- ){ 11 for( int i = 0; i <

HDU BestCoder Round #1 1002 项目管理

项目管理 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 0    Accepted Submission(s): 0 Problem Description 我们建造了一个大项目!这个项目有n个节点,用很多边连接起来,并且这个项目是连通的! 两个节点间可能有多条边,不过一条边的两端必然是不同的节点. 每个节点都有一个能量值. 现在我们