Noip 2003T1 神经网络

18 篇文章 0 订阅
14 篇文章 0 订阅

题目:

 神经网络

来源:

 Noip 2003T1

题目大意:

 从输入层开始,各节点按照传递公式,一层一层向下传递。输出输出层中信号大于零  的节点编号和信号大小。(节点编号由小到大)如果没有满足条件的编号则输出  NULL。
       信号传递公式:Ci=∑(j→i)Cj*Wji-Ui  
       公式中的Wji(可能为负值)表示连接j号神经元和i号神经元的边的权值。当Ci大  于0时,该神经元处于兴奋状态,否则就处于平静状态。当神经元处于兴奋状态时,  下一秒它会向其它神经元传递信号,信号的强度为Ci

数据范围:

 1≤n≤200

样例:

 5 6

 1 0

 1 0

 0 1

 0 1

 0 1

 1 3 1

 1 4 1

 1 5 1

 2 3 1

 2 4 1

 2 5 1

3 1
4 1
5 1

做题思路:

 广搜,注意C是>0是才向下传,输出时按从小到大。这次代码写的好猥琐。。。。

知识点:

 Bfs

type
 edge=record
 y,next,w:longint;
 end;
var
 a:array[0..500]of edge;
 d,first,c:array[0..500]of longint;
 q:array[0..200000]of longint;
 b:array[0..500]of boolean;
 n,p,tot:longint;
 pc:boolean;
procedure ad_edge(x,y,w:longint);
begin
 inc(tot);
 a[tot].y:=y;
 a[tot].w:=w;
 a[tot].next:=first[x];
 first[x]:=tot;
end;
procedure init;
var
 i,x,y,w,sum:longint;
begin
 readln(n,p);
 fori:=1 to n do
  begin
  readln(x,y);
   ifx<>0 then
   begin
    c[i]:=x;{<输入点C>0>}
    end
   else
   begin
    c[i]:=-y; {<非输入点的C=0,而且后面要用到U,所以提前赋给他省得麻烦>}
   end;
  end;
 tot:=0;
 fori:=1 to p do
  begin
  readln(x,y,w);
  ad_edge(x,y,w);
  end;
end;
procedure bfs;
var
 head,tail,t,i:longint;
begin
 fillchar(b,sizeof(b),false);
 head:=1;tail:=0;
 fori:=1 to n do 
  ifc[i]>0 then
  begin
   inc(tail);
   q[tail]:=i;
   b[i]:=true;
   end;
 tot:=0;
 whilehead<=tail do
  begin
  t:=first[q[head]];
   ift>0 then{<有传出点的继续bfs,没有的记录下来等待输出>}
  begin
   ifc[q[head]]>0 then{<大于0的才传递这让我丢了一次分>}
  while t>0 do
   begin
    c[a[t].y]:=c[a[t].y]+a[t].w*c[q[head]];
     ifnot b[a[t].y] then
     begin
      inc(tail);
      q[tail]:=a[t].y;
      b[a[t].y]:=true;
     end;
    t:=a[t].next;
   end;
   end
   else
    begin
    inc(tot);
    d[tot]:=q[head];
   end;
  b[q[head]]:=false;
  inc(head);
  end;
end;
procedure qsort(l,r:longint);
var
 i,j,k,t:longint;
begin
 i:=l;j:=r;
 k:=d[(l+r)shr 1];
 repeat
  whiled[i]<k do inc(i);
  whiled[j]>k do dec(j);
  ifi<=j then
  begin
   t:=d[i];d[i]:=d[j];d[j]:=t;
   inc(i);dec(j);
   end;
 untili>j;
 ifi<r then qsort(i,r);
 ifj>l then qsort(l,j);
end;
procedure outit;
var
 i,m:longint;
begin
 qsort(1,tot);
 pc:=false;
 m:=-maxlongint;
 fori:=1 to tot do
  if c[d[i]]>0 then{<题目要求只输出大于0的>}
  begin
   pc:=true;
    if(m<>d[i]) then{<bfs记录时猥琐了,所以这里只能继续猥琐——判重>}
    begin
     writeln(d[i],' ',c[d[i]]);
     m:=d[i];
    end;
   end;
 if notpc then writeln('NULL');
end;
begin
 assign(input,'network.in');reset(input);
 assign(output,'network.out');rewrite(output);
 init;
 bfs;
 outit;
 close(input);close(output);
end.
题目来源: http://yt.tyvj.cn:8080/Problem_Show.asp?id=1038


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值