比赛 20110730 评测结果 WWTTTTTEWW
题目名称 翻硬币 最终得分 0
用户昵称 lizhe 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2011-07-30 12:47:18
显示代码纯文本
program xcoins;
var
  n,min,yu,shang:int64;
  hash:array[0..10000000]of boolean;
procedure init;
begin
  assign(input,'xcoins.in');
  reset(input);
  assign(output,'xcoins.out');
  rewrite(output);
  read(n);
  yu:=n mod 5;
  shang:=(n-yu-5) div 5;
  if yu=0 then
    min:=n div 5;
  if yu=1 then
    min:=shang+6;
  if yu=2 then
    min:=shang+3;
  if yu=3 then
    min:=shang+3;
  if yu=4 then
    min:=shang+2;
  fillchar(hash,sizeof(hash),true)
end;

procedure dfs(step,X,O:longint);
var
  i:longint;
begin
  if step>min then
    exit;
  if (O=n) and (min>step) then
    min:=step
  else
  begin
    for i:=0 to X do
      if (i<=5) and hash[abs((i-5)*i+i) mod 100000] and (i<=X) and (5-i<=O) then
      begin
        hash[(X*O+X) mod 100000]:=false;
      	dfs(step+1,X-2*i+5,O+2*i-5);
        hash[(X*O+X) mod 100000]:=true
      end
  end
end;

procedure print;
begin
  writeln(min);
  close(input);
  close(output)
end;

begin
  init;
  dfs(0,n,0);
  print
end.