poj2613

来源:互联网 发布:切片软件是什么? 编辑:程序博客网 时间:2024/05/16 08:02

【题意】

求C(q,p)/C(r,s)的值,保留五位小数

【输入】

多组数据,每组数据一行为q、p、r、s

【输出】

对于每组数据,输出一个数表示C(q,p)/C(r,s)的值


将因数分解后约分再从大到乘除即可


program poj2613;var  p,q,r,s,i,j,k:longint;  ans:extended;  count:array [0..10001] of longint;begin  while not seekeof do    begin      fillchar(count,sizeof(count),0);      read(p,q,r,s);      for i:=2 to p do        inc(count[i]);      for i:=2 to q do        dec(count[i]);      for i:=2 to p-q do        dec(count[i]);      for i:=2 to r do        dec(count[i]);      for i:=2 to s do        inc(count[i]);      for i:=2 to r-s do        inc(count[i]);      ans:=1;      for i:=10000 downto 2 do        if count[i]>0 then          begin            for j:=1 to count[i] do              ans:=ans*i;          end                      else        if count[i]<0 then          begin            for j:=1 to -count[i] do              ans:=ans/i;          end;      writeln(ans:0:5);    end;end.


原创粉丝点击