zoukankan      html  css  js  c++  java
  • P1226神经网络

      提交了7次,看了无数题解,要死啊~~~。(无限吐槽这道题。。。

      据说是Toposort,我其实也不是很清楚,反正BFS就可以过;写题之前先把题看懂;

      根据公式,因为入度为零的点不会被传递,所以阈值是无用的,所以那个阈值除入度为零的点以外可以直接减去(读题最重要!!!),而搜索就是从入度为零(即没有边指向的这个点)开始的,所以输入时就记录一下入读和出度;传递就规规矩矩的模拟就行了,细节很多,多加注意,切切切...

      

    #include <bits/stdc++.h>
    
    using namespace std;
    
    #define INF 0x3f3f3f3f
    #define MAXN 1000000
    #define MAXM 5000
    #define D 10
    
    inline int read()
    {
        int x = 0,ff = 1;char ch = getchar();
        while(!isdigit(ch))
        {
            if(ch == '-') ff = -1;
            ch = getchar();
        }
        while(isdigit(ch))
        {
            x = (x<<1) + (x<<3) + (ch ^ 48);
            ch = getchar();
        }
        return x * ff;
    }
    
    inline void write(int x)
    {
        if(x < 0) putchar('-'),x = -x;
        if(x > 9) write(x / 10);
        putchar(x % 10 + '0');
    }
    
    int n,b,x,y,v,tot = 0,head = 1,tail = 0,ans = 0;
    int flag[MAXN + D],value[MAXN + D],q[MAXN + D];
    int r[MAXN + D],c[MAXN + D];
    int a[MAXM + D][MAXM + D],vis[MAXN + D];
    
    void BFS()
    {
        for(head = 1;head <= tail;++head)
        {
            int m = q[head]; vis[m] = false;
            if(flag[m] <= 0) continue;
            for(int i = 1;i <= n;++i)
            {
                if(a[m][i])
                {
                    flag[i] += a[m][i] * flag[m] ;
                    if(!vis[i])
                    {
                        q[++tail] = i;
                        vis[i] = true;
                    }
                }
            }
        }
    }
    
    int main()
    {
        memset(a,0,sizeof(a));
        n = read(); b = read();
        for(int i = 1;i <= n;++i)
        {
            flag[i] = read();
            value[i] = read();
            if(!flag[i]) flag[i] -= value[i];
            else 
            {
                q[++tail] = i;
                vis[i] = true;
            }
        }
        for(int i = 1;i <= b;++i)
        {
            x = read(); y = read(); v = read();
            a[x][y] = v;
            r[y]++; c[x]++;
        }
        BFS();
        for(int i = 1;i <= n;++i)
        if(flag[i] > 0&&!c[i])
        {
            ans = 1;
            write(i); putchar(' '); write(flag[i]);
            putchar('
    ');
        }
        if(!ans) printf("NULL");
        return 0;
    }
  • 相关阅读:
    记一道乘法&加法线段树(模版题)
    2021CCPC网络赛(重赛)题解
    Codeforces Round #747 (Div. 2)题解
    F. Mattress Run 题解
    Codeforces Round #744 (Div. 3) G题题解
    AtCoder Beginner Contest 220部分题(G,H)题解
    Educational Codeforces Round 114 (Rated for Div. 2)题解
    Codeforces Global Round 16题解
    Educational Codeforces Round 113 (Rated for Div. 2)题解
    AtCoder Beginner Contest 182 F
  • 原文地址:https://www.cnblogs.com/AK-ls/p/10232824.html
Copyright © 2011-2022 走看看