NOIP 2003

传送门

http://cojs.tk/cogs/problem/problem.php?pid=104
http://cojs.tk/cogs/problem/problem.php?pid=105
http://cojs.tk/cogs/problem/problem.php?pid=106
http://cojs.tk/cogs/problem/problem.php?pid=107

T1 神经网络

题解

woc,尼玛这个题目的描述啊,输出非0!答案里全是输出正的!
好了,我们来简单说一下,按拓扑序的方法依次求过去即可

var
 t,w:array[0..200,0..200]of longint;
 ans,x,u,c,z,y:array[0..200]of longint;
 i,j,k:longint;
 n,m:longint;
 a,b,d:longint;
begin
 fillchar(y,sizeof(y),0);
 readln(n,m);
 for i:=1 to n do
  begin readln(c[i],u[i]); end;
 for i:=1 to m do
  begin
   readln(a,b,d);
   t[a,b]:=d; w[a,b]:=1;
   inc(y[b]);
  end;

 for i:=1 to n do
  if y[i]=0 then begin
   for j:=1 to n do
    if w[i,j]=1 then inc(z[j]);
   x[i]:=-1;
  end;
 for i:=1 to n do
  dec(y[i],z[i]);
 for i:=1 to n do
  if x[i]<>-1 then c[i]:=-u[i];

 repeat
 k:=0;
 fillchar(z,sizeof(z),0);
 for i:=1 to n do
  if (x[i]<>-1)and(y[i]=0) then begin
   for j:=1 to n do
    if (c[j]>0)and(w[j,i]=1) then begin k:=1; inc(c[i],t[j,i]*c[j]); end;
   for j:=1 to n do
    if (w[i,j]=1)and(x[j]<>-1)
    then inc(z[j]);
   x[i]:=-1;
  end;
 for i:=1 to n do
  dec(y[i],z[i]);
 until k=0;

 for i:=1 to n do
  begin
   k:=0;
   for j:=1 to n do
    if (w[i,j]=1) then begin k:=1; break; end;
   if (k=0) then begin inc(ans[0]); ans[ans[0]]:=i; end;
  end;
 k:=1;
 for i:=1 to ans[0] do
  if c[ans[i]]<>0 then k:=0;
 if k=0 then begin
 for i:=1 to ans[0] do
  if c[ans[i]]>0
  then writeln(ans[i],' ',c[ans[i]]); end
 else writeln('NULL');
end.

T2 侦探推理

T3 加分二叉树

T4 传染病控制

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值