题意:

给一个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. PAT (Basic Level) Practise (中文)- 1011. A+B和C (15)

    http://www.patest.cn/contests/pat-b-practise/1011 给定区间[-231, 231]内的3个整数A.B和C,请判断A+B是否大于C. 输入格式: 输入第1 ...

  2. iOS下的2D仿射变换机制(CGAffineTransform相关)

    仿射变换简介 仿射变换源于CoreGraphics框架,主要作用是绘制2D级别的图层,几乎所有iOS设备屏幕上的界面元素都是由CoreGraphics来负责绘制.而我们要了解的2D仿射变换是其下负责二 ...

  3. jq 下拉框

    <div class="alls"> <div class="item"> <div class="all"& ...

  4. JavaScript递归实现对象深拷贝

    let personOne = { name:"张三", age:18, sex:"male", children:{ first:{ name:"z ...

  5. css3中的nth-child和nth-of-type的区别

    实例: 首先创建一个HTML结构 <div class="post"> <p>我是文章的第一段落</p> <p>我是文章的第二段落& ...

  6. Android驱动开发读书笔记五

    第五章 本章介绍了S3C6410开发板的功能,开发板的不同主要是在烧录嵌入式系统的方式不同,以及如何在此开发板上安装Android. 1.安装串口调试工具minicom 首先需要一根USB转串口线,由 ...

  7. 学习笔记(三): Generalization/Overfitting/Validation

      目录 Generalization: Peril of Overfitting Low loss, but still a bad model? How Do We Know If Our Mod ...

  8. 获得函数返回值类型、参数tuple、成员函数指针中的对象类型

    //function_traits.h,获得函数返回值类型.参数tuple.成员函数指针中的对象类型 //参考https://github.com/qicosmos/cosmos/blob/maste ...

  9. MongoDB - 启动&连接数据库

    1> 启动数据库 1.1> 依次添加如下目录: 1.1.1> mongodb-space 1.1.2> mongodb-space/conf 1.1.3> mongodb ...

  10. ubuntu安装easygui模块

    使用pip安装easygui 如果未安装pip,则使用如下命令 sudo apt-get install python-pip 安装完pip后,使用如下命令安装easygui sudo pip ins ...