切换到宽版
  • 6589阅读
  • 2回复

NOIP2009 提高组问题求解和阅读程序题 [复制链接]

上一主题 下一主题
离线hjwz
 
只看楼主 倒序阅读 0 发表于: 2009-10-17
问题求解(doc文件)          求解第1题答案(据称),见2楼
阅读程序PAS文件(RAR压缩包)

第一题:
  1. var a,b:integer;
  2. function work(a,b:integer):integer;
  3. begin
  4.         if a mod b <>0 then
  5.                 work:=work(b,a mod b)
  6.         else
  7.                 work:=b;
  8. end;
  9. begin
  10.         read(a,b);
  11.         writeln(work(a,b));
  12. end.
输入:123 321
输出:_________
key:3


第二题:
  1. var a,b:array[0..3] of integer;
  2.         i,j,tmp:integer;
  3. begin
  4.         for i:=0 to 3 do
  5.                 read(b);
  6.         for i:=0 to 3 do
  7.         begin
  8.                 a:=0;
  9.                 for j:=0 to i do
  10.                 begin
  11.                         inc(a,b[j]);
  12.                         inc(b[a mod 4],a[j]);
  13.                 end;
  14.         end;
  15.         tmp:=1;
  16.         for i:=0 to 3 do
  17.         begin
  18.                 a:=a mod 10;
  19.                 b:=b mod 10;
  20.                 tmp:=tmp*(a+b);
  21.         end;
  22.         writeln(tmp);
  23. end.

输入:2 3 5 7
输出:____________

key: 5850


第三题:
  1. const y=2009;
  2.         maxn=50;
  3. var
  4.         n,i,j,s:longint;
  5.         c:array[0..maxn,0..maxn] of longint;
  6. begin
  7.         s:=0;
  8.         read(n);
  9.         c[0,0]:=1;
  10.         for i:=1 to n do
  11.         begin
  12.                 c[i,0]:=1;
  13.                 for j:=1 to i-1 do
  14.                         c[i,j]:=c[i-1,j-1]+c[i-1,j];
  15.                 c[i,i]:=1;
  16.         end;
  17.         for i:=0 to n do
  18.                 s:=(s+c[n,i]) mod y;
  19.         write(s);
  20. end.

输入:17
输出:________

key:487


第四题:
  1. var n,m,i,j,k,p:integer;
  2.         a,b:array[0..100] of integer;
  3. begin
  4.         read(n,m);
  5.         a[0]:=n;
  6.         i:=0; p:=0; k:=0;
  7.         repeat
  8.                 for j:=0 to i-1 do
  9.                         if a=a[j] then
  10.                         begin
  11.                                 p:=1; k:=j;
  12.                                 break;
  13.                         end;
  14.                 if p<>0 then break;
  15.                 b:=a div m;
  16.                 a[i+1]:=(a mod m)*10;
  17.                 inc(i);
  18.         until a=0;
  19.         write(b[0],'.');
  20.         for j:=1 to k-1 do
  21.                 write(b[j]);
  22.         if p<>0 then
  23.         write('(');
  24.         for j:=k to i-1 do write(b[j]);
  25.         if p<>0 then write(')');
  26.         writeln;
  27. end.

输入:5 13
输出:_________

key:0.(384615)
离线hjwz
只看该作者 1 发表于: 2009-10-17
  1. program toponum;
  2. var a:array[0..1000,0..1000]of longint;
  3.      ind:array[1..1000]of longint;
  4.      c:array[1..1000]of boolean;
  5.      num,n,m,ans:longint;
  6.   procedure init;
  7.    var i,j,x,y:longint;
  8.     begin
  9.      readln(n,m);
  10.      for i:=1 to m do
  11.       begin
  12.        readln(x,y);
  13.        a[x,y]:=1;
  14.        inc(ind[y]);
  15.       end;
  16.     end;
  17.   procedure predo;
  18.    var i,j:longint;
  19.     begin
  20.      num:=n;
  21.      for i:=1 to n do
  22.       if ind=0 then
  23.        begin
  24.         a[0,i]:=1;
  25.         ind:=1;
  26.        end;
  27.     end;
  28.   procedure topo(v:integer);
  29.    var i,j:longint;
  30.     begin
  31.      if num=0 then begin inc(ans);exit;end;
  32.      for i:=1 to n do
  33.       if a[v,i]>0 then
  34.         dec(ind);
  35.      for i:=1 to n do
  36.       if (ind=0)and(not c) then
  37.        begin
  38.         c:=true;
  39.         dec(num);
  40.         topo(i);
  41.         c:=false;
  42.         inc(num);
  43.        end;
  44.      for i:=1 to n do
  45.       if a[v,i]>0 then
  46.        inc(ind);
  47.     end;
  48.   begin
  49.    init;
  50.    predo;
  51.    topo(0);
  52.    writeln(ans);
  53.   end.


输入数据:
9 8
1 2
1 5
2 3
3 4
3 7
7 6
8 9
4 6

输出数据:
432
离线zhangyoufu
只看该作者 2 发表于: 2009-10-17
顶,,和我做的一样
快速回复
限100 字节
 
上一个 下一个