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.
  • 相关阅读:
    ubuntu 用shell脚本实现将当前文件夹下全部文件夹中的某一类文件复制到同一文件夹下
    读书笔记-2java虚拟机的可达性算法与finalize方法
    find the longest of the shortest (hdu 1595 SPFA+枚举)
    杭电 2176 取(m堆)石子游戏(博弈)
    MVC框架的优缺点
    Wireshark-TCP协议分析(包结构以及连接的建立和释放)
    Ubuntu安装教程--Win7系统中含100M保留分区
    eclipse新建android项目出现非常多错误
    关于简单的加密和解密算法
    在一台server上部署多个Tomcat
  • 原文地址:https://www.cnblogs.com/myx12345/p/6013417.html
Copyright © 2011-2022 走看看