题解

116 条题解

  • 0
    @ 2015-06-01 10:28:54

    直接模拟做的,开始忘记考虑权值为非正数(直接用k[i][j]>0判断有没有边)结果WA了好多次

    #include<stdio.h>
    int main( )
    {

    int n,p,c[205]={0},u[205]={0},k[205][205],i,j,a,b,flag=0,d,flag2=0,flag3=0,pd[205][205];

    for(i=1;i<=204;i++)
    for(j=1;j<=204;j++)
    {k[i][j]=0;pd[i][j]=0;}

    scanf("%d %d",&n,&p);

    for(i=1;i<=n;i++)
    scanf("%d %d",&c[i],&u[i]);

    for(i=1;i<=p;i++)
    {
    scanf("%d %d %d",&a,&b,&d);
    k[b][a]=d;
    pd[b][a]=1;
    }

    for(i=1;i<=n;i++)
    {
    for(j=i-1;j>=1;j--)
    if (pd[i][j]==1 && c[j]>0) {c[i]=c[i]+c[j]*k[i][j];flag3=1;}

    if(flag3==1) c[i]=c[i]-u[i];
    flag3=0;
    }

    for(i=1;i<=n;i++)
    {
    for(j=i;j<=n;j++)
    if(pd[j][i]==1) flag2=1;

    if (flag2==0 && c[i]>0) {printf("%d %d\n",i,c[i]);flag=1;}
    flag2=0;
    }

    if(flag==0) printf("NULL");

    return 0;
    }

  • 0
    @ 2015-04-10 21:59:56

    显然的拓扑排序,不断求解无依赖关系(即入度为0)的点的值,删点,再求,直至所有点求解完毕。但鉴于题目描述过于坑爹,还是在这里说明一下:
    1. 图有负权边。初始化时千万不能把邻接矩阵赋0,而应赋正无穷。
    2. 只输出值**大于0**而不是**非0**的**输出层**点(即出度为0且值大于0的点)。
    3. 点的值可能为正,可能为负,但是带负值的点并不传导任何信号。

    /*为了清晰起见,我定义了4个常量,用以指代点的不同信息。STATUS代表点的值,
    THRESHOLD代表阈值,IN代表入度,OUT代表出度*/

    #include <stdio.h>
    #include <limits.h>

    #define STATUS 0
    #define THRESHOLD 1
    #define IN 2
    #define OUT 3

    int map[300][300];
    int vertices[300][4];

    int main(){
    int numVertex,numEdge;
    int i,k,from,to,value,flag;

    scanf("%d %d",&numVertex,&numEdge);
    for(i=0;i<numVertex;i++){
    for(k=0;k<numVertex;k++)
    map[i][k]=LONG_MAX;
    }
    for(i=0;i<numVertex;i++){
    scanf("%d %d",&vertices[i][STATUS],&vertices[i][THRESHOLD]);
    vertices[i][IN]=0;
    vertices[i][OUT]=0;
    }
    for(i=0;i<numEdge;i++){
    scanf("%d %d %d",&from,&to,&value);
    from--,to--;
    map[from][to]=value;
    vertices[to][IN]++;
    vertices[from][OUT]++;
    }

    for(i=0;i<numVertex;i++){
    for(from=0;from<numVertex;from++){
    if(vertices[from][IN]==0)
    break;
    }
    if(from>=numVertex){
    //error: there must be a cycle.
    }
    vertices[from][IN]=-1;

    value=0;
    flag=0;
    for(k=0;k<numVertex;k++){
    if(map[k][from]<LONG_MAX){
    if(vertices[k][STATUS]>0)
    value += vertices[k][STATUS] * map[k][from];
    flag=1;
    }
    }
    if(flag)
    vertices[from][STATUS] = value-vertices[from][THRESHOLD];

    for(to=0;to<numVertex;to++){
    if(map[from][to]<LONG_MAX)
    vertices[to][IN]--;
    }
    }

    flag=0; //check if at least vertex is active
    for(i=0;i<numVertex;i++){
    if(vertices[i][OUT]==0 && vertices[i][STATUS]>0){
    flag=1;
    printf("%d %d\n",i+1,vertices[i][STATUS]);
    }
    }
    if(!flag)
    printf("NULL\n");

    return 0;
    }

    • @ 2015-08-28 13:46:35

      为毛先拓扑再处理会出问题...

  • 0
    @ 2014-11-23 21:55:48

    #include<deque>
    #include<iostream>
    using namespace std;
    main()
    {
    bool f[201]={0},h[201]={0},l=0,o[201]={0};
    int a,b,c[201],i,m,n,u[201],w[201][201],x;
    deque<int>s;
    cin>>n>>m;
    for(i=0;i<n;i++)
    {
    cin>>c[i]>>u[i];
    if(c[i])
    {
    s.push_back(i);
    o[i]=1;
    }
    else
    c[i]=-1*u[i];
    }
    for(i=0;i<m;i++)
    {
    cin>>a>>b;
    cin>>w[--a][--b];
    h[a]=1;
    }
    while(!s.empty())
    {
    x=s.front();
    s.pop_front();
    o[x]=0;
    if(!h[x]&&c[x]>0)
    f[x]=1;
    if(c[x]>0)
    for(i=0;i<n;i++)
    {
    if(i==x||!w[x][i])
    continue;
    c[i]+=w[x][i]*c[x];
    if(!o[i])
    {
    s.push_back(i);
    o[i]=1;
    }
    }
    }
    for(i=0;i<n;i++)
    if(f[i])
    {
    cout<<i+1<<' '<<c[i]<<endl;
    l=1;
    }
    if(!l)
    cout<<"NULL";
    }

  • 0
    @ 2012-08-12 10:47:08

    两年前看这道题,看不懂...特别是一开始的那副神经网络图很让人不爽

    今天硬着头皮再看这道题,原来是一道水题,深感出题人的脑残

    里面有几个细节要注意(可以帮助理解):

    1 w可能为负值(题目已经说了)

    2 仅当前面的神经元已经传了信息给第i个神经元后,这个神经元才能确定状态

    3 如果c[i]>0 (处于兴奋状态) ,那么这第i个神经元才能传递信息

    4 题目描述有问题,应该只需输出c[i]>0的神经元,而如果所有神经元的状态都

  • 0
    @ 2012-08-06 21:40:58

    写题目的多小心一点

  • 0
    @ 2012-08-01 11:17:20

    编译通过... 

    ├ 测试数据 01:答案正确... 0ms 

    ├ 测试数据 02:答案正确... 0ms 

    ├ 测试数据 03:答案正确... 0ms 

    ├ 测试数据 04:答案正确... 0ms 

    ├ 测试数据 05:答案正确... 0ms 

    ---|---|---|---|---|---|---|---|- 

    Accepted 有效得分:100 有效耗时:0ms 

    感谢楼下提醒,输出时只输出大于0的结点

    1A 无压力 5min 敲代码

  • 0
    @ 2010-07-23 01:05:17

    汗~~我也交了7次~~

    一开始没有明白权值等于0的问题所在

    后来发现在模拟的时候碰到路径0直接返回,没有去掉这条边,导致入度记录出错,所以错了第二点

  • 0
    @ 2010-07-17 22:16:23

    确实神经

  • 0
    @ 2010-04-13 21:52:48

    1.拓扑排序

    2.讯号强度是累加的

    3.边权可以是负数,0,正数

    4.输出(输出层的状态大于0的点)

    5.vijos的数据虽然没有,但是n可以=1

    ——————————————————————

    我的AC率啊(+.+)

    ——————————————————————

    贴代码:

    const

    max=999999999;

    var

    n,p:longint;

    c,u,r,link,ans,f:array[1..200]of longint;

    g,map:array[1..200,1..200]of longint;

    v:array[1..200]of boolean;

    procedure init;

    var

    i,j,a,b,s:longint;

    begin

    readln(n,p);

    fillchar(c,sizeof(c),0); fillchar(u,sizeof(u),0);

    for i:=1 to n do

    readln(c[i],u[i]);

    for i:=1 to n do for j:=1 to n do map:=max;

    fillchar(r,sizeof(r),0);

    fillchar(v,sizeof(v),true);

    for i:=1 to p do

    begin

    readln(a,b,s);

    map[a,b]:=s;

    inc(r);

    v[a]:=false;

    end;

    end;

    procedure swap(var a,b:longint);

    var

    t:longint;

    begin

    t:=a; a:=b; b:=t;

    end;

    procedure topsort;

    var

    i,j,k,s:longint;

    flag:boolean;

    begin

    fillchar(f,sizeof(f),0);

    i:=1;

    link:=r;

    g:=map;

    while i0 then

    begin

    s:=0;

    for j:=1 to i-1 do

    if (map[f[j],f[i]]max) and (c[f[j]]>0) then inc(s,map[f[j],f[i]]*c[f[j]]);

    c[f[i]]:=c[f[i]]+s-u[f[i]];

    end;

    flag:=true;

    for i:=1 to n do

    if v[f[i]] and (c[f[i]]0) then flag:=false;

    if flag then writeln('NULL')

    else

    begin

    for i:=1 to n-1 do

    for j:=i+1 to n do

    if v[f[i]] and v[f[j]] and (f[i]>f[j]) then

    begin

    swap(f[i],f[j]);

    swap(c[f[i]],c[f[j]]);

    end;

    for i:=1 to n do

    if v[f[i]] and (c[f[i]]>0) then writeln(f[i],' ',c[f[i]]);

    end;

    end;

    begin

    init;

    topsort;

    end.

  • 0
    @ 2009-11-04 20:48:26

    小弟不才,还请各位大牛多多指点 ^_^

    var n,p,i,x,y:longint;

    boo:boolean;

    c,d,u,ru,chu:array[0..100] of longint;

    a:array[0..100,0..100] of longint;

    g:array[0..100,0..100] of longint;

    procedure asd(k:longint);

    var i:longint;

    begin

    if chu[k]=0 then exit;

    for i:=1 to chu[k] do

    begin

    asd(g[k,i]);

    if c[g[k,i]]>0 then c[k]:=c[k]+a[g[k,i],k]*c[g[k,i]];

    end;

    end;

    begin

    readln(n,p);

    for i:=1 to n do

    begin

    readln(c[i],u[i]);

    if c[i]=0 then c[i]:=c[i]-u[i];

    end;

    for i:=1 to p do

    begin

    readln(x,y,a[x,y]);

    inc(ru[x]);

    inc(chu[y]);

    g[y,chu[y]]:=x;

    end;

    boo:=true; d:=c;

    for i:=1 to n do

    if ru[i]=0 then

    begin

    c:=d;

    asd(i);

    if c[i]>0 then

    begin

    writeln(i,' ',c[i]);

    boo:=false;

    end;

    end;

    if boo then writeln('NULL');

    end.

  • 0
    @ 2009-11-04 16:50:53

    我还用了记忆化搜索。。。

    var

    n,e:longint;

    f:array[1..100] of longint;

    a:array[1..100] of longint;

    d:array[1..100] of longint;

    fa:array[1..100] of longint;

    c:array[1..100,1..100,1..2] of longint;

    pd:array[1..100] of boolean;

    x,y,z:longint;

    i,j,k:longint;

    p:boolean;

    procedure search(k:longint);

    var

    i:longint;

    begin

    if pd[k] then

    exit;

    pd[k]:=true;

    if fa[k]=0 then

    exit;

    for i:=1 to fa[k] do

    begin

    search(c[k,i,1]);

    if f[c[k,i,1]]>0 then

    f[k]:=f[k]+f[c[k,i,1]]*c[k,i,2];

    end;

    dec(f[k],a[k]);

    end;

    begin

    readln(n,e);

    for i:=1 to n do

    readln(f[i],a[i]);

    for i:=1 to e do

    begin

    readln(x,y,z);

    inc(d[x]);

    inc(fa[y]);

    c[y,fa[y],1]:=x;

    c[y,fa[y],2]:=z;

    end;

    for i:=1 to n do

    if d[i]=0 then

    begin

    search(i);

    if f[i]>0 then

    begin

    writeln(i,' ',f[i]);

    p:=true;

    end;

    end;

    if not p then

    writeln('NULL');

    end.

  • 0
    @ 2009-11-03 10:36:45

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案错误... ├ 标准行输出 NULL

     ├ 错误行输出 null

    ├ 测试数据 05:答案正确... 0ms

    ---|---|---|---|---|---|---|---|-

    Unaccepted 有效得分:80 有效耗时:0ms

    没天理呀!我明明是大写,它非说我是小写

  • 0
    @ 2009-10-26 20:42:18

    这题考的不是技术,是细心

  • 0
    @ 2009-10-24 21:12:10

    简单模拟

    细节超多。。。。关键在于N=1的情况要判断

    怪不得那年分数线那么低,原来都是题目没看懂

  • 0
    @ 2009-10-19 23:25:18

    program v1105;

    var g:array[1..200,1..200] of longint;

    u,o,f,e:array[1..200] of longint;

    t:array[1..200] of boolean;

    i,j,k,n,m,x,y:longint;

    can:boolean;

    procedure search(p:longint);

    var i:longint;

    begin

    if t[p]=true then exit;

    for i:=1 to n do

    if g0

    then begin

    search(i);

    if f[i]>0 then inc(f[p],f[i]*g);

    end;

    t[p]:=true;

    end;

    begin

    readln(n,m);

    for i:=1 to n do readln(f[i],u[i]);

    for i:=1 to m do

    begin

    readln(x,y,g[x,y]);

    inc(o[x]);

    inc(e[y]);

    end;

    can:=false;

    fillchar(t,sizeof(t),0);

    for i:=1 to n do

    if e[i]=0 then t[i]:=true else dec(f[i],u[i]);

    for i:=1 to n do

    if o[i]=0

    then begin

    search(i);

    if f[i]>0

    then begin

    writeln(i,' ',f[i]);

    can:=true;

    end;

    end;

    if not can then writeln('NULL');

    end.

    呼~~~~~

  • 0
    @ 2009-10-18 10:27:58

    var

    n,m,i,j,k,a,b,t,w,maxdep,tmp:longint;

    c,u,dep,h:array[1..200] of longint;

    g:array[1..200,1..200] of longint;

    f:boolean;

    begin

    readln(n,m);

    w:=0;

    for i:=1 to n do begin

    readln(c[i],u[i]);

    if c[i]0 then begin

    inc(w);

    h[w]:=i;

    dep[i]:=0;

    end;

    end;

    for i:=1 to m do begin

    readln(a,b,t);

    g[a,b]:=t;

    end;

    for i:=w+1 to n do begin

    tmp:=0;

    for j:=1 to n do if (g[j,i]0) and (c[j]>0)then begin

    tmp:=tmp+g[j,i]*c[j];

    dep[i]:=dep[j]+1;

    end;

    c[i]:=tmp-u[i];

    if dep[i]>maxdep then maxdep:=dep[i];

    end;

    f:=true;

    for i:=1 to n do if (dep[i]=maxdep) and (c[i]>0)then f:=false;

    if f then write('NULL') else for i:=1 to n do if (dep[i]=maxdep) and (c[i]>0)then writeln(i,' ',c[i]);

    end.

    也还简单啊。。主要是最后是大于0才输出!不是非0,orz题目、、。。。

  • 0
    @ 2009-10-11 18:34:01

    没什么难度的题 直接广搜

    ---|---|---|---|---|---|---|---|---|---|晒程序---|---|---|---|---|---|---|---|---|-

    program p1105;

    var

    n,p,k,i,j,x1,x2,x3:longint;

    flag:boolean;

    c,b,u:array[0..300]of longint;

    w:array[0..300,0..300]of longint;

    begin

    readln(n,p);

    for i:=1 to n do

    begin

    readln(c[i],u[i]);

    b[i]:=-1;

    if c[i]>0 then b[i]:=0;

    end;

    for i:=1 to p do

    begin

    readln(x1,x2,x3);

    w[x1,x2]:=x3;

    end;

    flag:=true;

    k:=0;

    while flag do

    begin

    flag:=false;

    for i:=1 to n do

    if b[i]=k then

    begin

    if k0 then c[i]:=c[i]-u[i];

    if c[i]>0 then

    begin

    for j:=1 to n do

    if (w0)and((b[j]=-1)or(b[j]=k+1)) then

    begin

    flag:=true;

    inc(c[j],w*c[i]);

    b[j]:=k+1;

    end;

    end;

    end;

    inc(k);

    end;

    flag:=false;

    for i:=1 to n do

    if (b[i]=k-1)and(c[i]>0) then

    begin

    flag:=true;

    writeln(i,' ',c[i]);

    end;

    if not flag then

    writeln('NULL');

    end.

  • 0
    @ 2009-10-09 09:28:03

    输入层不考虑阈值!!!

    输出c[i]>0的神经元!!!

    什么题意...

    又臭又长...还对着数据调好久...

  • 0
    @ 2009-10-08 12:41:27

    1、输入层不考虑阈值;

    2、c[i]0的神经元

    4、切记输出‘null’;

    BFS过

    真是一道神经题

  • 0
    @ 2009-10-06 11:28:57

    模拟过的

    交了4次才AC,分别错了三个地方

    1.题目描述问题。c[i]>0时才输出

    2.若c[i]>0而i没连边的话就不传递

    3.忘了输NULL(这个就是自己的问题了)

信息

ID
1105
难度
6
分类
搜索 | 搜索与剪枝 点击显示
标签
递交数
4342
已通过
1260
通过率
29%
被复制
16
上传者