zoukankan      html  css  js  c++  java
  • 【CF679B】Theseus and labyrinth(数学,贪心)

    题意:

    给一个m<=10^15,每次都减最接近当前值的立方数

    让你找一个不大于m的最大的数并且这个数是减法次数最多的数

    思路:见http://blog.csdn.net/miracle_ma/article/details/52458715

            开始想用贪心直接写

            后面发现步数是对的,但使原数最大很难处理,因为各个i^3之间i的差不都<=1

            于是用DFS处理

            以下是大神题解:

            a3m 
            如ama3 
            取a1Xa31a31(a1)3 
            如a2a1a1 
            所aa1 
            如xa 
            所XX 
            最X 
            比xa1xa31(a1)3 
            那X 
            所dfsa3

           

     1 var f:array[1..100001]of qword;
     2     n,ans1,ans2:qword;
     3     i:longint;
     4 
     5 function clac(x:qword):qword;
     6 var l,r,mid,last:qword;
     7 begin
     8  l:=1; r:=trunc(sqrt(x)); last:=l;
     9  while l<=r do
    10  begin
    11   mid:=(l+r)>>1;
    12   if mid*mid<=x div mid then begin last:=mid; l:=mid+1; end
    13    else r:=mid-1;
    14  end;
    15  exit(last);
    16 end;
    17 
    18 procedure dfs(s1,k,s2:qword);
    19 var p:qword;
    20 begin
    21  if s1=0 then
    22  begin
    23   if (k>ans1)or((k=ans1)and(s2>ans2)) then begin ans1:=k; ans2:=s2; end;
    24   exit;
    25  end;
    26  p:=clac(s1);
    27  dfs(s1-f[p],k+1,s2+f[p]);
    28  if p>1 then dfs(f[p]-1-f[p-1],k+1,s2+f[p-1]);
    29 end;
    30 
    31 begin
    32 // assign(input,'1.in'); reset(input);
    33  //assign(output,'1.out'); rewrite(output);
    34  readln(n);
    35  for i:=1 to 100001 do begin f[i]:=i; f[i]:=f[i]*f[i]*f[i]; end;
    36  ans1:=1; ans2:=1;
    37  dfs(n,0,0);
    38  writeln(ans1,' ',ans2);
    39  //close(input);
    40  //close(output);
    41 end.
  • 相关阅读:
    HDU 1058 Humble Numbers
    HDU 1160 FatMouse's Speed
    HDU 1087 Super Jumping! Jumping! Jumping!
    HDU 1003 Max Sum
    HDU 1297 Children’s Queue
    UVA1584环状序列 Circular Sequence
    UVA442 矩阵链乘 Matrix Chain Multiplication
    DjangoModels修改后出现You are trying to add a non-nullable field 'download' to book without a default; we can't do that (the database needs something to populate existing rows). Please select a fix:
    opencv做的简单播放器
    c++文件流输入输出
  • 原文地址:https://www.cnblogs.com/myx12345/p/6013417.html
Copyright © 2011-2022 走看看