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

    #include <bits/stdc++.h>
    using namespace std;
    const int maxn = 105;
    struct node
    {
    	int situation, yuzhi;
    }ns[maxn];
    std::vector<int> g[maxn];
    int main() {
    	int n, p;
    	cin >> n >> p;
    	queue<int> q;
    	int vis[maxn];
    	bool qidian[maxn];
    	memset(vis, 0, sizeof(vis));
    	for(int i = 1; i <= n; i++) {
    		cin >> ns[i].situation >> ns[i].yuzhi;
    		if(ns[i].situation) {
    			q.push(i);
    			qidian[i] = 1;
    			vis[i] = 1;
    		}
    	}
    	int weigh[maxn][maxn];
    	for(int i = 1; i <= p; i++) {
    		int x, y, z;
    		cin >> x >> y >> z;
    		g[x].push_back(y);
    		weigh[x][y] = z;
    	}
    	while(!q.empty()) {
    		int x = q.front();
    		q.pop();
    		if(!qidian[x]) ns[x].situation -= ns[x].yuzhi;
    		if(ns[x].situation > 0) {
    			vector<int>::iterator it;
    			for(it = g[x].begin(); it != g[x].end(); it++) {
    				ns[*it].situation += weigh[x][*it] * ns[x].situation;
    				if(!vis[*it]) {
    					q.push(*it);
    					vis[*it] = 1;
    				}
    			}
    		}
    	}
    	bool flag = true;
    	for(int i = 1; i <= n; i++) {
    		if(g[i].empty() && ns[i].situation > 0) {
    			flag = false;
    			cout << i << ' ' << ns[i].situation << endl;
    		}
    	}
    	if(flag) cout << "NULL"; 
    }
    
  • 相关阅读:
    Redis单机操作
    Scala
    RDD算子
    Python学习之旅(七)
    python学习之旅(六)
    python学习之旅(五)
    python学习之旅(四)
    python学习之旅(二)
    python学习之旅(三)
    Python学习之旅(一)
  • 原文地址:https://www.cnblogs.com/gengchen/p/6058803.html
Copyright © 2011-2022 走看看