POJ 3842(质数判断)

7!=5040

所以这题直接求质数比打一千万的表都快

这提高诉我们阶乘其实不算大&看(算)清数据规模


Program cc;
var
   n,t,len,i,j,ans:longint;
   s:string;
   b:array[0..9] of longint;
procedure dfs(p,l:longint);
var
   i:longint;
begin
   if l=len then
   begin
      if p=1 then exit;
      for i:=2 to trunc(sqrt(p)) do if (p mod i=0) then exit;
      inc(ans);
      exit;
   end;
   for i:=0 to 9 do
   if b[i]>0 then
   begin
      if (i=0) and (l=0) then continue;
      dec(b[i]);
      dfs(p*10+i,l+1);
      inc(b[i]);
   end;

end;
begin
   readln(t);
   while (t>0) do
   begin
      readln(s);
      len:=length(s);
      fillchar(b,sizeof(b),0);
      for i:=1 to len do inc(b[ord(s[i])-48]);
      ans:=0;
      for i:=1 to len do
      begin
         dfs(0,0);
         dec(len);
      end;
      writeln(ans);


      dec(t);
   end;
end.

POJ 3122(二分答案)

二分答案……

Program pie;
const
   lef=0.00001;
var
   t,n,f,i,j:longint;
   r:array[1..10000] of longint;
   s:array[1..10000] of double;
   maxs:double;
procedure sort(l,r:double);
var
   m:real;
   i,j,tot:longint;
begin
   m:=(l+r)/2;
   tot:=0;
   for i:=1 to n do inc(tot,trunc(s[i]/m));

   if tot>=f then
   begin
      if r-l<lef then writeln(r:4:4)
      else sort(m,r);


   end
   else sort(l,m);










end;
begin
   read(t);
   while (t>0) do
   begin
      read(n,f);
      inc(f);
      for i:=1 to n do
      begin
         read(r[i]);
         s[i]:=sqr(r[i])*pi;
      end;
      maxs:=s[1];
      for i:=2 to n do
         if maxs<s[i] then maxs:=s[i];
      sort(0,maxs);

      dec(t);
   end;
end.