A.二叉树的的根
题目:http://www.contesthunter.org/contest/CH%20Round%20%2349%20-%20Streaming%20%234%20(NOIP 模拟赛Day2)/二叉树的根
题解:自己yy一下就出来了。。。
如果有度数超过3的节点,则不可能成为2叉树,直接输出0即可
否则,树中度数为1和2的点都可以作为根
代码:
var i,n,x,y,tot:longint;
a,d:array[..] of longint;
procedure init;
begin
readln(n);
for i:= to n- do
begin
readln(x,y);inc(d[x]);inc(d[y]);
end;
end;
procedure main;
begin
tot:=;
for i:= to n do
if d[i]>= then begin writeln();exit;end
else if d[i]<= then begin inc(tot);a[tot]:=i;end;
writeln(tot);
write(a[]);
for i:= to tot do write(' ',a[i]);
end; begin
init;
main;
end.
B.距离统计
题目:http://www.contesthunter.org/contest/CH%20Round%20%2349%20-%20Streaming%20%234%20(NOIP模拟赛Day2)/距离统计
题解:正解不可做。。。写暴力还写跪了。。。本来能骗50分,结果最后只有10分。。。
代码:
var tmp,n,m,t,r,x,k:int64;
i,j:longint;
ans:int64;
procedure init;
begin
readln(n,m,t);
if n>m then begin tmp:=n;n:=m;m:=tmp;end;
end;
procedure main;
begin
for i:= to t do
begin
read(r);ans:=;
if m>r then inc(ans,n*(m-r));
if n>r then inc(ans,m*(n-r));
for j:= to trunc(r/sqrt()) do
begin
x:=sqr(r)-sqr(j);
if x<sqr(j) then break;
if trunc(sqrt(x))=sqrt(x) then
begin
k:=trunc(sqrt(x));
if m>k then inc(ans,*(n-j)*(m-k));
if n>k then inc(ans,*(n-k)*(m-j));
end;
end;
write(ans,' ');
end;
end;
begin
init;
main;
end.
C.电阻网络
题目:http://www.contesthunter.org/contest/CH%20Round%20%2349%20-%20Streaming%20%234%20(NOIP模拟赛Day2)/电阻网络
题解:我表示电阻都不会算了。。。果断弃疗。。。