讨论 / 求解。。。。。谁跟我说说哪错了
wsxtyrdd 2012-04-17 07:23:00
点我顶贴 收藏 删除
var i,n,k,j,t,s,x,y,fx,fy,d:longint;

f,g:array[0..50000]of longint;

function get(u:longint):longint;

begin

if f[u]=u then exit(f[u])

else

begin

g[u]:=(g[u]+g[f[u]])mod 3;

f[u]:=get(f[u]);

exit(f[u]);

end;

end;

begin

read(n,k);

for i:=1 to n do

f[i]:=i;

for i:=1 to k do

begin

read(d,x,y);

if (d=2)and(x=y) then begin s:=s+1;continue; end;

if (x>n)or(y>n) then begin s:=s+1;continue; end;

fx:=get(x);

fy:=get(y);

if d=1 then begin

if fx<>fy then begin f[fy]:=x;g[fy]:=(3-g[y]) mod 3; continue; end;

if fx=fy then if g[x]<>g[y] then s:=s+1; end;

if d=2 then begin

if fx<>fy then begin f[fy]:=x;g[fy]:=2-g[y];continue; end;

if fx=fy then begin

if fy=y then begin if g[x]<>1 then s:=s+1;continue;end;

t:=0;

if ((g[x]=1)and(g[y]=0))or((g[x]=2)and(g[y]=1))or((g[x]=0)and(g[y]=2)) then

t:=1;

if t<>1 then s:=s+1;end;

end;

end;

write(s);

end.

只能过第1.2.10 点

#1 wsxtyrdd@2012-04-16 02:10:00
回复 删除
。。。。。。。

食物链 。。。。哪位大牛来看看

分不够可以加

#2 mahaozhou@2012-04-16 21:25:00
回复 删除
加油加油

加油加油

#3 wsxtyrdd@2012-04-17 07:23:00
回复 删除
....同志们 搞定了

....蛋定了

查看状态 Show Status

题目:[NOI2001]食物链

状态: Accepted

测评机: Xeost[5]

得分: 100分 [我要评价一下题目~]

提交日期: 2012-4-17 22:22:00

有效耗时: 2202毫秒

RQNOJ近期在线比赛列表

RQNOJ2012五月省选特别赛 时间:2012-X-X 13:00:00 [报名]

测试结果1: 通过本测试点|有效耗时203ms

测试结果2: 通过本测试点|有效耗时172ms

测试结果3: 通过本测试点|有效耗时171ms

测试结果4: 通过本测试点|有效耗时172ms

测试结果5: 通过本测试点|有效耗时172ms

测试结果6: 通过本测试点|有效耗时172ms

测试结果7: 通过本测试点|有效耗时281ms

测试结果8: 通过本测试点|有效耗时281ms

测试结果9: 通过本测试点|有效耗时297ms

测试结果10: 通过本测试点|有效耗时281ms

提交代码: view sourceprint?01.var i,n,k,j,t,s,x,y,fx,fy,d:longint;

02.

f,g:array[0..50000]of longint;

03.function get(u:longint):longint;

04.var v:longint;

05.begin

06.if f[u]=u then exit(f[u]);

07.v:=f[u];

08.f[u]:=get(f[u]);

09.g[u]:=(g[u]+g[v])mod 3;

10.exit(f[u]);

11.end;

12.begin

13.read(n,k);

14.for i:=1 to n do

15.f[i]:=i;

16.for i:=1 to k do

17.begin

18.read(d,x,y);

19.if (d=2)and(x=y) then begin s:=s+1;continue; end;

20.if (x>n)or(y>n) then begin s:=s+1;continue; end;

21.fx:=get(x);

22.fy:=get(y);

23.if d=1 then begin

24.if fx<>fy then begin f[fy]:=x;g[fy]:=(3-g[y]) mod 3; continue; end;

25.if fx=fy then if g[x]<>g[y] then s:=s+1; end;

26.if d=2 then begin

27.if fx<>fy then begin f[fy]:=x;g[fy]:=2-g[y];continue; end;

28.if fx=fy then begin

29.if fy=y then begin if g[x]<>1 then s:=s+1;continue;end;

30.if (g[x]+2) mod 3<>g[y] then

31.s:=s+1;

32.end;

33.end;

34.end;

35.write(s);

36.end

查看更多回复
提交回复