1 条题解
-
0
C++ :
//神经网络 #include <iostream> #include <algorithm> #include <cstring> #include <cstdio> #include <queue> #include <cctype> using namespace std; const int N = 205; struct Edge{ int to,next,wei; }edge[N * N]; struct Node{ int c,u; Node (){ c = 0; u = 0; } }g[N]; int head[N],edgen = 0,rudu[N],n,p; bool chudu[N]; inline int Read(){ bool neg = false; char tmp = getchar(); int rtn = 0; while (!isdigit(tmp)){ if (tmp == '-') neg = true; tmp = getchar(); } while (isdigit(tmp)){ rtn = rtn * 10 + tmp - '0'; tmp = getchar(); } if (neg) rtn -= 2*rtn; return rtn; } inline void Add_Edge(int x,int y,int w){ edge[edgen].to = y; edge[edgen].next = head[x]; edge[edgen].wei = w; head[x] = edgen++; } void Rudu(){ for (int i = 1;i <= n; i++) for (int p = head[i];p != -1;p = edge[p].next) rudu[edge[p].to]++,chudu[i] = true; } int search(int k){ if (!chudu[k]) return g[k].c; int rtn = 0; for (int p = head[k];p != -1;p = edge[p].next){ int use = search(edge[p].to); if (use > 0) rtn += use * edge[p].wei; } rtn -= g[k].u; return rtn; } int main(){ n = Read(),p = Read(); for (int i = 1;i <= n; i++){ g[i].c = Read(); g[i].u = Read(); } memset(head,-1,sizeof(head)); for (int i = 1,x,y,w;i <= p; i++){ x = Read(); y = Read(); w = Read(); Add_Edge(y,x,w); } memset(rudu,0,sizeof(rudu)); memset(chudu,false,sizeof(chudu)); Rudu(); bool flag = false; for (int i = 1;i <= n; i++) if (!rudu[i]){ int use = search(i); if (use > 0){ cout << i << " " << use << endl; flag = true; } } if (!flag) cout << "NULL\n"; return 0; } /* 6 8 1 0 1 0 0 1 0 1 0 1 0 1 1 3 5 1 4 3 2 3 1 2 4 2 4 6 2 4 5 1 3 5 2 3 6 1 */ /* 7 7 2 0 4 0 0 1 0 1 0 1 0 1 0 1 1 3 -2 1 4 1 3 6 -1 4 6 3 4 7 5 2 5 1 5 7 -1 */
Pascal :
const maxn=200;maxp=200; var i,j,n,p,maxlayer:integer; w:array[0..maxp]of longint; start,terminal:array[0..maxp]of byte; u,c:array[0..maxn]of longint; layer:array[0..maxn]of byte; flag:boolean; begin readln(n,p); for i:=1 to n do readln(c[i],u[i]); fillchar(layer,sizeof(layer),0); for i:=1 to p do begin readln(start[i],terminal[i],w[i]); layer[terminal[i]]:=layer[start[i]]+1; end; maxlayer:=layer[terminal[p]]; for i:=1 to n do if layer[i]>0 then begin for j:=1 to p do if (terminal[j]=i)and(c[start[j]]>0) then c[i]:=c[i]+w[j]*c[start[j]]; c[i]:=c[i]-u[i]; end; flag:=true; for i:=1 to n do if (layer[i]=maxlayer) and (c[i]>0) then begin writeln(i,' ',c[i]); flag:=false; end; if flag then writeln('NULL'); end.
- 1
信息
- ID
- 226
- 时间
- 1000ms
- 内存
- 125MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者