1076 Neural Networks

Source: Internet
Author: User
Description

[Problem background] artificial neural network is a new computing system with self-learning ability, it is widely used in many fields such as pattern recognition, function approximation, and loan risk assessment. The Study of neural networks has always been a hot topic today. After learning a neural network introductory book, lan LAN proposed a simplified model, he hopes that you can help him use a program to test the practicality of the neural network model. [Problem description] In the Lanlan model, a neural network is a directed graph. the nodes in the graph are called neurons, and the two neurons have at most one edge. An example of a neuron is as follows:

In the neuron (numbered 1) diagram, the X1-X3 is the information input channel, the Y1-Y2 is the information output channel, C1 represents the current state of the neuron, the UI is the threshold, can be seen as an internal parameter of the neuron. Neurons are arranged in a certain order to form the entire neural network. In Lanlan's model, neural networks do not have several layers of neural networks. They are called the input layer, output layer, and several intermediate layers. Each layer of neurons only outputs information from the next layer of neurons, and only receives information from the previous layer of neurons. Is an example of a simple layer-3 neural network.

According to Lanlan, CI follows the formula: (n indicates the number of all neurons in the Network)

In the formula, wji (which may be negative) indicates the weight of the edge connecting the neuron J and neuron I. When Ci is greater than 0, the neuron is in the excited state, otherwise it is in the calm state. When a neuron is excited, it will send signals to other neurons in the next second, and the signal intensity is CI. In this way, after the Input-layer neurons are activated, the entire network system operates under the impetus of information transmission. Now, given a neural network and the State (CI) of the neurons in the current input layer, your program is required to calculate the state of the final network output layer.

Input

Each test point has several test data. The first row of test data in each group is two integers, n (1 ≤ n ≤ 200) and P. In the next n rows, there are two integers in each row. Row I + 1 is the initial state of neuron I and its threshold (UI). The State of neurons in the non-input layer must be 0 at the beginning. Next, in the p row, each line consists of two integers I, j and an integer wij, indicating that the edge weights of connected neurons I and j are wij. The test data ends at least two zeros.

Output

Each group of test data contains several rows. Each row has two integers, corresponding to the number of a neuron and its final state. The two integers are separated by spaces. Only outputs the state of the non-Zero output layer neurons in the final state, and outputs the state in ascending order of numbers! If the final state of the neuron in the output layer is 0, null is output.

Sample Input
5 61 01 00 10 10 11 3 11 4 11 5 12 3 12 4 12 5 10 0
Sample output
3 14 15 1
Source
Noip 2003 (by dyp)

 

This question should be related to graph theory and need to be searched continuously

 

#include <iostream>#define MAX 201using namespace std;class tqueue{private:class tnode{public:int v;tnode *next;tnode(int tv){v=tv;next=0;}};tnode *first,*last;public:int size;bool in[MAX];tqueue(){first=last=0;size=0;memset(in,0,sizeof(in));}void ins(int v){in[v]=true;if (size)last=last->next=new tnode(v);elsefirst=last=new tnode(v);size++;}int pop(){int rtn=first->v;in[rtn]=false;tnode *t=first;first=first->next;delete t;size--;return rtn;}};class node{public:node *next;int p,v;node(int tp,int tv){p=tp;v=tv;next=0;}};class tadjl{public:node *f,*l;tadjl(){f=l=0;}void ins(int p,int v){if (f)l=l->next=new node(p,v);elsef=l=new node(p,v);}};tqueue Q;tadjl adjl[MAX];int C[MAX],U[MAX];int N,P;bool lastlevel[MAX];bool firstlevel[MAX];void init(){int i,a,b,v;cin >> N >> P;if(!(N==0&&P==0)){    memset(lastlevel,0,sizeof(lastlevel));memset(firstlevel,0,sizeof(firstlevel));memset(adjl,0,sizeof(adjl));for (i=1;i<=N;i++){cin >> C[i] >> U[i];if (C[i]>0){Q.ins(i);firstlevel[i]=true;}}for (i=1;i<=P;i++){cin >> a >> b >> v;adjl[a].ins(b,v);}}}void solve(){int i,j,v;node *k;while (Q.size){i=Q.pop();if (!firstlevel[i])C[i]-=U[i];if (C[i]<0) continue;if (!adjl[i].f)lastlevel[i]=true;for (k=adjl[i].f;k;k=k->next){j=k->p;v=k->v;C[j]+=v*C[i];if (!Q.in[j])Q.ins(j);}}}void print(){int i;bool none=true;for (i=1;i<=N;i++){if (lastlevel[i] && C[i]!=0){cout << i << ' ' << C[i] << endl;none=false;}}if (none)printf("NULL\n");}int main(){init();while(!(N==0&&P==0)){solve();print();   init();}return 0;}

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.