CH Round #49 - Streaming #4 (NOIP模拟赛Day2)

A.二叉树的的根

题目:http://www.contesthunter.org/contest/CH%20Round%20%2349%20-%20Streaming%20%234%20(NOIP 模拟赛Day2)/二叉树的根

题解:自己yy一下就出来了。。。

如果有度数超过3的节点,则不可能成为2叉树,直接输出0即可

否则,树中度数为1和2的点都可以作为根

代码:

 1 var i,n,x,y,tot:longint;
 2     a,d:array[0..150000] of longint;
 3 procedure init;
 4  begin
 5    readln(n);
 6    for i:=1 to n-1 do
 7     begin
 8       readln(x,y);inc(d[x]);inc(d[y]);
 9     end;
10  end;
11 procedure main;
12  begin
13    tot:=0;
14    for i:=1 to n do
15     if d[i]>=4 then begin writeln(0);exit;end
16     else if d[i]<=2 then begin inc(tot);a[tot]:=i;end;
17    writeln(tot);
18    write(a[1]);
19    for i:=2 to tot do write(' ',a[i]);
20  end;
21 
22 begin
23   init;
24   main;
25 end.     
View Code

B.距离统计

题目:http://www.contesthunter.org/contest/CH%20Round%20%2349%20-%20Streaming%20%234%20(NOIP模拟赛Day2)/距离统计

题解:正解不可做。。。写暴力还写跪了。。。本来能骗50分,结果最后只有10分。。。

代码:

 1 var tmp,n,m,t,r,x,k:int64;
 2     i,j:longint;
 3     ans:int64;
 4 procedure init;
 5  begin
 6    readln(n,m,t);
 7    if n>m then begin tmp:=n;n:=m;m:=tmp;end;
 8  end;
 9 procedure main;
10  begin
11    for i:=1 to t do
12     begin
13       read(r);ans:=0;
14       if m>r then inc(ans,n*(m-r));
15       if n>r then inc(ans,m*(n-r));
16       for j:=1 to trunc(r/sqrt(2)) do
17         begin
18           x:=sqr(r)-sqr(j);
19           if x<sqr(j) then break;
20           if trunc(sqrt(x))=sqrt(x) then
21            begin
22             k:=trunc(sqrt(x));
23             if m>k then inc(ans,2*(n-j)*(m-k));
24             if n>k then inc(ans,2*(n-k)*(m-j));
25            end;
26         end;
27      write(ans,' ');
28     end;
29  end;
30 begin
31   init;
32   main;
33 end.     
View Code

C.电阻网络

题目:http://www.contesthunter.org/contest/CH%20Round%20%2349%20-%20Streaming%20%234%20(NOIP模拟赛Day2)/电阻网络

题解:我表示电阻都不会算了。。。果断弃疗。。。

 

posted @ 2014-08-16 13:24  ZYF-ZYF  Views(264)  Comments(0Edit  收藏  举报