题意:

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

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

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

开始想用贪心直接写

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

于是用DFS处理

以下是大神题解:

考虑第一块取多少,最大的a3≤m 
        如果取a,还剩m−a3 
        取a−1的话,那肯定最大的X是a3−1,剩下a3−1−(a−1)3 
        如果取a−2的话,肯定没有a−1来的优,因为剩下的比取a−1剩下的要少 
        所以就是取a或者a−1,然后对于每次剩下的都可以这么考虑 
        如果你问,剩下x的时候,不是应该要取最大的a么 
        所以我们开头假设的X,不一定是最终的X 
        最后根据你取的,重新安排开头的X 
        比如这会剩x,然后取a−1,x当作了a3−1−(a−1)3 
        那么只要在最开始的时候X取小一点就行了 
        所以dfs的时候记录个数,还剩多少,∑a3

 var f:array[..]of qword;
n,ans1,ans2:qword;
i:longint; function clac(x:qword):qword;
var l,r,mid,last:qword;
begin
l:=; r:=trunc(sqrt(x)); last:=l;
while l<=r do
begin
mid:=(l+r)>>;
if mid*mid<=x div mid then begin last:=mid; l:=mid+; end
else r:=mid-;
end;
exit(last);
end; procedure dfs(s1,k,s2:qword);
var p:qword;
begin
if s1= then
begin
if (k>ans1)or((k=ans1)and(s2>ans2)) then begin ans1:=k; ans2:=s2; end;
exit;
end;
p:=clac(s1);
dfs(s1-f[p],k+,s2+f[p]);
if p> then dfs(f[p]--f[p-],k+,s2+f[p-]);
end; begin
// assign(input,'1.in'); reset(input);
//assign(output,'1.out'); rewrite(output);
readln(n);
for i:= to do begin f[i]:=i; f[i]:=f[i]*f[i]*f[i]; end;
ans1:=; ans2:=;
dfs(n,,);
writeln(ans1,' ',ans2);
//close(input);
//close(output);
end.

【CF679B】Theseus and labyrinth(数学,贪心)的更多相关文章

  1. Codeforces Round #354 (Div. 2) D. Theseus and labyrinth bfs

    D. Theseus and labyrinth 题目连接: http://www.codeforces.com/contest/676/problem/D Description Theseus h ...

  2. 【25.93%】【676D】Theseus and labyrinth

    time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  3. 洛谷3月月赛div2 题解(模拟+数学+贪心+数学)

    由于本人太蒻了,div1的没有参加,胡乱写了写div2的代码就赶过来了. T1 苏联人 题目背景 题目名称是吸引你点进来的. 这是一道正常的题,和苏联没有任何关系. 题目描述 你在打 EE Round ...

  4. UVALive 7147 World Cup(数学+贪心)(2014 Asia Shanghai Regional Contest)

    题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&category=6 ...

  5. HDOJ 5073 Galaxy 数学 贪心

    贪心: 保存连续的n-k个数,求最小的一段方差... .预处理O1算期望. .. Galaxy Time Limit: 2000/1000 MS (Java/Others)    Memory Lim ...

  6. FZU 2144 Shooting Game(数学+贪心)

    主要思路:求出蚊子到达球的时间区间(用方程得解),对区间做一个贪心的选择,选择尽可能多的区间有交集的区间段(结构体排序即可),然后计数. #include <cstdio> #includ ...

  7. hdu 3573(数学+贪心)

    Buy Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  8. hdu 5747(数学,贪心)

    Aaronson Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total ...

  9. Codeforces Round #323 (Div. 2) C 无敌gcd 数学/贪心

    C. GCD Table time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

随机推荐

  1. inner join 和 left join 的区别

    1.left join.right join.inner join的区别 left join(左联接) 返回包括左表中的所有记录和右表中联结字段相等的记录 right join(右联接) 返回包括右表 ...

  2. Dapper学习总结

    看了<Dapper从入门到精通>后的总结 (1)Dapper 是直接扩展 IDBConnection,而且是单独一个文件,可以直接嵌入到项目中使用. (2)通过手写sql语句,调用exec ...

  3. C语言程序运行

    vs2013编辑器 c程序的运行   一.启动Microsoft Visual C++  2013版.新建项目 . 1.  文件——> 新建——> 项目.       2. 确定之后 弹出 ...

  4. 【NOIP提高A组模拟2018.8.14】 区间

    区间加:差分数组修改 O(n)扫描,负数位置单调不减 #include<iostream> #include<cstring> #include<cstdio> # ...

  5. Spring Security和Shiro的比较和使用

    https://blog.csdn.net/it_java_shuai/article/details/78054951 Spring Security和Shiro的比较和使用 2017年09月21日 ...

  6. springBoot 集成swagger2.9.2

    加依赖 <!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui --> <dependen ...

  7. 使用jquery清除select中的所有option

    html代码 <select id="search"> <option>baidu</option> <option>sogou&l ...

  8. destoon修改笔记

    $EXT = cache_read('module-3.php');  $EXT,存放了module3的设置 后台模型管理,扩展模型 里设置.     1.admin.php 后台管理项目对应文件. ...

  9. python计算机基础(三)

    简述Python垃圾回收机制: 当x=10,赋值x=11,的代码,也就是10没有对应的变量名, 10在python眼中相当于垃圾,就会被清理掉,释放内存. 对于下述代码: x = 10 y = 10 ...

  10. percpu之静态变量

    参考:Linux内核同步机制之(二):Per-CPU变量 CPU私有变量(per-CPU变量) 动态PCPU变量 setup_per_cpu_areas()初始化per-cpu数据. static v ...