P1038 neural network and p1038 Neural Network

Source: Internet
Author: User

P1038 neural network and p1038 Neural Network
Background

Artificial Neural Network (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.

Description

In the Lanlan model, a neural network is a directed graph. the nodes in the graph are called neurons, and the two neurons are connected by at most one edge. An example of a neuron is shown below:

Neuron (numbered 1)

In the figure, X1-X3 is the information input channel, Y1-Y2 is the information output channel, C1 represents the current state of neurons, Ui is the threshold, can be considered as an internal parameter of neurons.

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/Output Format Input Format:

The first line of the input file is two integers, n (1 ≤ n ≤ 100) 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.

Output Format:

The output file 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 status of the output-layer neurons whose last State is greater than zero, and outputs the status in ascending order of numbers!

If the final state of the neuron in the output layer is 0, NULL is output.

Input and Output sample Input example #1:
5 61 01 00 10 10 11 3 11 4 11 5 12 3 12 4 12 5 1
Output sample #1:
3 14 15 1

This question is generally difficult, but I will give a full score for the test data !! It's true that all the data has

Let's talk about the idea of this question.

Topology Sorting after reading, which is calculated according to the formula given by him during sorting

Let's talk about the pitfalls of this question:

1. The final output result is output only when the value is greater than 0.

2. The threshold value does not need to be reduced for points with an inbound value of 0 (this will lead to the fifth test point WA)

3. It is best to subtract the threshold value from the beginning.

4. You can determine the output area by recording the output degree.

  1 #include<iostream>  2 #include<cstdio>  3 #include<cstring>  4 #include<cmath>  5 #include<queue>  6 #include<cstdlib>  7 using namespace std;  8 void read(int & n)  9 { 10     char c='+';int x=0;int flag=0; 11     while(c<'0'||c>'9') 12     { 13         c=getchar(); 14         if(c=='-') 15         flag=1; 16     } 17     while(c>='0'&&c<='9') 18     x=x*10+(c-48),c=getchar(); 19     flag==1?n=-x:n=x; 20 } 21 const int MAXN=201; 22 struct node 23 { 24     int u,v,w,nxt; 25 }edge[MAXN*40]; 26 int head[MAXN]; 27 int num=1; 28 int now[MAXN],yu[MAXN],rudu[MAXN],vis[MAXN],chudu[MAXN]; 29 int n,m; 30 void add_edge(int x,int y,int z) 31 { 32     edge[num].u=x; 33     edge[num].v=y; 34     edge[num].w=z; 35     edge[num].nxt=head[x]; 36     head[x]=num++; 37 } 38 void Topsort() 39 { 40     queue<int>q; 41     for(int i=1;i<=n;i++) 42     { 43         if(rudu[i]==0) 44             vis[i]=1,q.push(i); 45         else 46             now[i]-=yu[i]; 47     } 48          49     while(q.size()!=0) 50     { 51         int p=q.front(); 52         q.pop(); 53         for(int i=head[p];i!=-1;i=edge[i].nxt) 54         { 55             rudu[edge[i].v]--; 56             if(rudu[edge[i].v]==0) 57             { 58                 q.push(edge[i].v); 59                 vis[edge[i].v]=1; 60             } 61             if(now[edge[i].u]>0) 62             now[edge[i].v]+=edge[i].w*now[edge[i].u]; 63         } 64     } 65     for(int i=1;i<=n;i++) 66     { 67         if(chudu[i]==0&&now[i]!=0) 68         { 69             for(int i=1;i<=n;i++) 70             { 71                 if(chudu[i]==0) 72                 { 73                     if(now[i]>0) 74                     printf("%d %d\n",i,now[i]); 75                 } 76             } 77             exit(0); 78         } 79     } 80     printf("NULL"); 81 } 82 int main() 83 { 84     ///freopen("sjwl.in","r",stdin); 85     //freopen("sjwl.out","w",stdout); 86     read(n);read(m); 87     for(int i=1;i<=n;i++) 88         head[i]=-1; 89     for(int i=1;i<=n;i++) 90     { 91         read(now[i]);read(yu[i]); 92     } 93     for(int i=1;i<=m;i++) 94     { 95         int x,y,z; 96         read(x);read(y);read(z); 97         add_edge(x,y,z); 98         rudu[y]++; 99         chudu[x]++;100     }101     Topsort();102     return 0;103 }

 




Related Article

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.