161 条题解

  • 0
    @ 2008-11-11 14:56:01

    var a:array[1..200,1..200] of boolean;

    n,x,i,j,k,total:integer;

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

    begin

    readln(n);

    fillchar(a,sizeof(a),false);

    fillchar(ok,sizeof(ok),false);

    for i:=1 to n do

    repeat

    a:=true;

    read(x);

    if x0 then begin a:=true; a[x,i]:=true; end;

    until x=0;

    for i:=1 to n do

    for j:=1 to n do

    if ij then

    for k:=1 to n do

    if (ik) and (jk) then

    if a and a then begin a[j,k]:=true; a[k,j]:=true; end;

    for i:=1 to n do

    if not ok[i] then begin

    ok[i]:=true;

    for j:=1 to n do

    if a then ok[j]:=true;

    inc(total);

    end;

    writeln(total);

    end.

  • 0
    @ 2008-11-09 14:56:14

    var

    n,m,i,j,k,l:longint;

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

    e,a:array[1..200,1..200]of boolean;

    procedure dfs(h:longint);

    var

    i:longint;

    begin

    for i:=1 to n do if(a[h,i])and(b[i]) then begin b[i]:=false;dfs(i);end;

    end;

    begin

    readln(n);

    fillchar(e,sizeof(e),false);

    fillchar(a,sizeof(a),false);

    for i:=1 to n do

    repeat

    read(j);

    if j=0 then break;

    e:=true;

    until j=0;

    for i:=1 to n do

    for j:=i+1 to n do

    if e and e[j,i] then

    begin

    a:=true;

    a[j,i]:=true;

    end;

    fillchar(b,sizeof(b),true);m:=0;

    for i:=1 to n do if b[i] then begin m:=m+1;dfs(i);end;

    writeln(m);

    end.

  • 0
    @ 2008-11-08 11:53:02

    并查集,哦也!

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

    编译通过...

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

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

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

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

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

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

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

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

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

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

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

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

    var i,n,ch,t,s,m:longint;a:array[1..200]of longint;

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

    function find(x:longint):longint;

    begin

    if a[x]=x then a[x]:=x

    else

    a[x]:=find(a[x]);

    find:=a[x];

    end;

    begin

    readln(n);

    for i:=1 to n do a[i]:=i;

    for i:=1 to n do

    begin

    read(ch);

    while ch0 do

    begin

    if a[i]a[ch] then

    begin

    t:=find(i);s:=find(ch);

    if ts then a:=t;

    end;

    read(ch);

    end;

    readln;

    end;

    fillchar(v,sizeof(v),0);

    m:=0;

    for i:=1 to n do t:=find(i);

    for i:=1 to n do

    if not(v[a[i]]) then

    begin

    inc(m);

    v[a[i]]:=true;

    end;

    writeln(m);

    end.

  • 0
    @ 2008-11-08 07:31:16

    program Ltr;

    var a:array[1..200,1..200] of boolean;

    f:array[1..200] of integer;

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

    i,j,tmp,n,s,min:integer;

    procedure work(x:integer);

    var i,j:integer;

    begin

    for i:=1 to n do if a[x,i] then begin

    a[x,i]:=false;

    f[i]:=f[x];

    work(i);

    end;

    end;

    function back(x:integer):integer;

    begin

    if f[x]=x then exit(x) else exit(f[x]);

    end;

    begin

    assign(input,'e:\in.txt');reset(input);

    readln(n);s:=0;

    fillchar(a,sizeof(a),false);

    for i:=1 to n do begin

    read(tmp);

    while tmp0 do begin

    a:=true;

    read(tmp);

    end;

    readln;

    end;

    for i:=1 to n do f[i]:=i;

    for i:=1 to n do work(i);

    fillchar(ha,sizeof(ha),false);

    for i:=1 to n do ha[f[i]]:=true;

    for i:=1 to n do if ha[i] then inc(s);

    writeln(s);

    end.

    10AC

  • 0
    @ 2008-11-07 09:34:34

    编译通过...

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

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

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

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

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

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

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

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

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

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

    核心代码:

    procedure search (x:integer);

    var

    i:integer;

    begin

    v[x]:=true;

    for i:=1 to child1[x] do

    if not v[map1[x,i]] then

    search (map1[x,i]);

    inc (sum);

    q[sum]:=x;

    end;

    procedure search1 (x:integer);

    var

    i:integer;

    begin

    v[x]:=true;

    for i:=1 to child2[x] do

    if not v[map2[x,i]] then

    search1 (map2[x,i]);

    inc (len);

    end;

    for i:=1 to n do

    if not v[i] then

    search (i);

    fillchar (v,sizeof (v),false);

    for i:=sum downto 1 do

    if not v[q[i]] then

    begin

    len:=0;

    search1 (q[i]);

    if len>1 then begin inc (ans); inc (t,len); end;

    end;

  • 0
    @ 2008-11-05 19:19:12

    Lsoe好猥琐!!!!!!!!!!!!1

    第一次做强连通分量啊。。。调了下样例。。交上来就直接对掉了。。。

    其实强连通分量也不是很难啊...建议没有编过的同学试一试。。

    编译通过...

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

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

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

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

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

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

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

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

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

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

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

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

  • 0
    @ 2008-10-27 10:20:44

    水啊!!!!

  • 0
    @ 2008-10-22 16:03:33

    编译通过...

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

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

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

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

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

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

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

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

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

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

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

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

    program p1022;

    var

    a:array [1..200,1..200] of integer;

    s,d:array [1..200] of integer;

    n,m,i,j,t,k,rear,front:integer;

    begin

    readln(n);

    for i:=1 to n do begin

    read(k);

    while k0 do begin

    a:=1;

    read(k);

    end;

    end;

    for i:=1 to n do

    begin

    for j:=1 to n do s[j]:=0;

    rear:=1;

    front:=1;

    d[1]:=i;

    s[i]:=1;

    while front0 do

    begin

    i:=1;

    inc(t);

    while s[i]=1 do inc(i);

    rear:=1;

    front:=1;

    d[1]:=i;

    dec(k);

    s[i]:=1;

    while front

  • 0
    @ 2008-10-21 22:49:50

    本题核心程序也就4,5行

  • 0
    @ 2008-10-20 21:50:23

    第一次写强连通分量!!

  • 0
    @ 2008-10-20 19:16:54

    var

    n,m:integer;

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

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

    procedure init;

    var i,j:integer;

    begin

    fillchar(g,sizeof(g),false);

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

    readln(n);

    for i:=1 to n do

    begin

    repeat

    read(j);

    if j0

    then g:=true;

    until j=0;

    readln;

    end;

    end;

    procedure work;

    var i,j,t,k:integer;

    b:array[1..200]of integer;

    change:boolean;

    begin

    for i:=1 to n do

    if v[i]

    then begin

    fillchar(b,sizeof(b),0);

    t:=1;

    v[i]:=false;

    b[t]:=i;

    repeat

    change:=false;

    for j:=1 to n do

    if v[j]

    then for k:=1 to t do

    if g[j,b[k]]and g[b[k],j]

    then begin

    inc(t);

    b[t]:=j;

    v[j]:=false;

    change:=true;

    break;

    end;

    until not change;

    inc(m);

    end;

    writeln(m);

    end;

    begin

    init;

    work;

    end.

  • 0
    @ 2008-10-16 21:12:14

    编译通过...

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

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

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

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

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

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

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

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

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

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

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

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

  • 0
    @ 2008-10-15 19:50:00

    编译通过...

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

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

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

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

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

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

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

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

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

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

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

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

    100题~

    注意要考虑传递性

  • 0
    @ 2008-10-11 20:39:13

    我对这数据完全无语了。。。(╯﹏╰)

  • 0
    @ 2008-10-09 15:39:13

    编译通过...

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

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

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

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

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

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

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

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

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

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

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

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

    很适合新手用来练习并查集(因为数据不像题目所说的那样复杂)

    只要以能否双向交流作为合并依据即可。。。

    同时可用该源程序过1023。。。

    #include

    int name[201][201];

    int parent[201];

    int rank[201];

    int FindSet(int i){

    if (parent[i]!=i)

    parent[i]=FindSet(parent[i]);//路径压缩

    return parent[i];

    }

    void UnionSet(int i,int j){

    i=FindSet(i);

    j=FindSet(j);

    if (i!=j)

    if (rank[i]>rank[j])//启发式合并:以根节点高度比较大的树的根作为新树的根

    parent[j]=i;

    else{

    parent[i]=j;

    if (rank[i]==rank[j])

    rank[j]++;

    }

    }

    main(){

    for (i=1;i

  • 0
    @ 2008-09-30 17:28:18

    编译通过...

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

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

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

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

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

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

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

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

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

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

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

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

    读数据错一次。。。

  • 0
    @ 2008-09-29 16:07:16

    并查集

    根据名单求出关系来就行了

  • 0
    @ 2008-09-14 10:40:19

    写个floodfill即可,瞬间AC,轻松、飘逸、潇洒、洒脱……

  • 0
    @ 2008-09-08 18:15:33

    编译通过...

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

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

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

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

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

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

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

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

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

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

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

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

  • 0
    @ 2008-09-06 17:54:56

    2的数据太弱了, 用3的代码居然过了,

    但题意不一样...

    总之, 烂题两道!

信息

ID
1022
难度
4
分类
图结构 点击显示
标签
递交数
4326
已通过
1981
通过率
46%
被复制
14
上传者