https://codeforces.com/contest/680/problem/D

一道2D,又是搞两个小时才搞出来。。。不过好在搞出来了

官方题解:可以证明对于m,设a是满足a^3<=m的最大a,那么选a或a-1一定最优;那么可以暴力dfs

....23333.。。。。。

完了,我也不知道为什么这个代码能A了


我的想法(仅做记录):对于m=m1的方案,如果最大的选a,那么说明X在[a^3,min((a+1)^3-1,m1)]区间内;这个区间的两个端点都减去a^3后,就发现m=m1的方案,相当于在m=min((a+1)^3-1,m1)-a^3时的方案上再补上取一个a

然后我打了一个很naive的暴力,就是枚举最大的数(设为i)。。根本不能A

考虑优化这个dp:

当m1<(i+1)^3-1即i>(m+1)的三次方根-1时,答案是m=m1-i^3时的答案补上取一个i,显然i变得更小时,答案的第一项不会变得更差,但是当答案的第一项相等时,i越大答案的第二项越好,因此暴力从最小的可能i枚举到最大的可能i,更新答案,如果发现枚举到某处时这一次得到的答案比当前总答案第一项劣,就跳出(所以其实是玄学暴力23333)

当m1>=(i+1)^3-1即i<=(m+1)的三次方根-1时,答案是m=(i+1)^3-i^3-1的答案补上取一个i,显然i变得更大时,答案总体不会变得更劣,因此只求i=(m+1)的三次方根-1时的答案即可

看了题解后发现自己这样搞其实有些无用的枚举(就比如第一种情况也是只考虑一个值就行了,这就是65行以后漏掉了对lt的赋值还能A的原因)

 #include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<map>
#include<cmath>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
const ll N=;
ll poww(ll x)
{
return x*x*x;
}
ll work(ll x)
{
ll t=pow(x,0.333333333333333333);
while(poww(t+)<=x) t++;
while(poww(t)>x) t--;
return t;
}
map<ll,pll> an;ll num;
//pll solve(ll m)
//{
// if(an.count(m)) return an[m];
// //num++;
// //if(num%100000==0) printf("%lld\n",num);
// //printf("%lld\n",m);
// //scanf("%d",new int);
// pll ans,t;ll tt;
// for(ll i=1;i<=N;i++)
// {
// tt=poww(i);
// if(tt>m) break;
// //if(poww(i+1)-1>m) break;
// t=solve(min(m,poww(i+1)-1)-tt);
// t.fi++;t.se+=tt;
// ans=max(ans,t);
// }
// return an[m]=ans;
//}
pll solve(ll m)
{
if(an.count(m)) return an[m];
pll ans(-,-),t,lt(-,-);ll t3=work(m+)-;
if(t3>&&t3<=N)
{
t=solve(poww(t3+)-poww(t3)-);
t.fi++;t.se+=poww(t3);
ans=t;
}
if(t3!=m)
{
for(ll i=t3+;i<=N;i++)
{
if(m-poww(i)<) break;
t=solve(m-poww(i));
if(lt.fi!=-&&lt.fi!=t.fi) break;
t.fi++;t.se+=poww(i);
ans=max(ans,t);
}
}
return an[m]=ans; } int main()
{
ll m;
an[]=mp(,);
scanf("%lld",&m);
auto t=solve(m);
printf("%lld %lld\n",t.fi,t.se);
return ;
}

Bear and Tower of Cubes Codeforces - 680D的更多相关文章

  1. Codeforces 680D Bear and Tower of Cubes 贪心 DFS

    链接 Codeforces 680D Bear and Tower of Cubes 题意 求一个不超过 \(m\) 的最大体积 \(X\), 每次选一个最大的 \(x\) 使得 \(x^3\) 不超 ...

  2. Codeforces 680D - Bear and Tower of Cubes

    680D - Bear and Tower of Cubes 思路:dfs+贪心,设剩余的体积为res,存在a,使得a3 ≤ res,每次取边长为a的立方体或者边长为a-1的立方体(这时体积上限变成a ...

  3. codeforces 680D D. Bear and Tower of Cubes(dfs+贪心)

    题目链接: D. Bear and Tower of Cubes time limit per test 2 seconds memory limit per test 256 megabytes i ...

  4. Codeforces Round #356 (Div. 2) D. Bear and Tower of Cubes dfs

    D. Bear and Tower of Cubes 题目连接: http://www.codeforces.com/contest/680/problem/D Description Limak i ...

  5. 【CodeForces】679 B. Bear and Tower of Cubes

    [题目]B. Bear and Tower of Cubes [题意]有若干积木体积为1^3,2^3,...k^3,对于一个总体积X要求每次贪心地取<=X的最大积木拼上去(每个只能取一次)最后总 ...

  6. 【19.05%】【codeforces 680D】Bear and Tower of Cubes

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

  7. CodeForces 679B(Bear and Tower of Cubes)

    题意:Limak要垒一座由立方体垒成的塔.现有无穷多个不同棱长(a>=1)的立方体.要求:1.塔的体积为X(X<=m).2.在小于X的前提下,每次都选体积最大的砖块.3.在砖块数最多的前提 ...

  8. uva 10051 Tower of Cubes(DAG最长路)

    题目连接:10051 - Tower of Cubes 题目大意:有n个正方体,从序号1~n, 对应的每个立方体的6个面分别有它的颜色(用数字给出),现在想要将立方体堆成塔,并且上面的立方体的序号要小 ...

  9. Anya and Cubes CodeForces - 525E (双端搜索)

    大意: 给定$n$元素序列$a$, 可以任选不超过$k$个$a_i$变换为$a_i!$, 求变换后任选若干元素和为S的方案数. 分成两块暴搜, 复杂度$O(3^{\frac{n}{2}})$ #inc ...

随机推荐

  1. 升级python到最新2.7.13

    python2.7是2.X的最后一个版本,同时也加入了一部分3.X的新特性.并且具有更好的性能,修改多个bug.所以决定升级到最新的2.7版,我的目前的版本是2.6.6 查看当前python版本 # ...

  2. RobotFramework教程使用笔记——RobotFramework的安装配置

    (一)  Python的安装和pip配置 首先,从Python的官方网站 www.python.org http://www.python.org/ftp/python 然后,运行下载的MSI安装包, ...

  3. U盘安装Ubuntu 14.04 LTS正式版 出现如下的提示,不能继续,如何操作?

    I had a problem (minor annoyance) when booting up Arch linux with a USB drive connected. The problem ...

  4. Mongodb GridFS——适合大小超过16MB的文件

    一.概述 GridFS是基于mongodb存储引擎是实现的“分布式文件系统”,底层基于mongodb存储机制,和其他本地文件系统相比,它具备大数据存储的多个优点.GridFS适合存储超过16MB的大型 ...

  5. Java中的final和static

    final final可以用在类.方法.变量上. 1.final用在类上,表明当前类它不能被继承,没有子类. 2.final用在方法上,表明当前方法不能被override,不能被重写. 3.final ...

  6. git 错误 Reinitialized existing Git repository in /**/***/ 和refusing to merge unrelated histories

    报错一: 这句话的意思是 在路径 /Users/jackma/Downloads/lotteryTicket 2/.git/ 现有的Git存储库初始化 ➜ lotteryTicket 2 git:(m ...

  7. 机器学习之SVM支持向量机

    前言            以下内容是个人学习之后的感悟,转载请注明出处~ 简介 支持向量机(support vector machine),简称SVM,通俗来讲,它是一种二类分类模型,其基本模型定义 ...

  8. awk里面执行shell命令

    先把文件列表存在filename文件中 先 awk '{system("rm $0")}' filename -------WRONG 因为对于 system来说 $0 不再是某行 ...

  9. http://www.cnblogs.com/dasenglin/p/5821987.html

    一安装maven 先安装jdk,配置JAVA_HOME 把下载的maven bin包,解压到指定目录,比如:D:\apache-maven-3.3.9-bin 配置maven的系统变量M2_HOME和 ...

  10. Flutter实战视频-移动电商-44.详细页_首屏自定义Widget编写

    44.详细页_首屏自定义Widget编写 把详细页的图片.标题.编号和价格形成一个单独的widget去引用 详情页的顶部单独封装个插件 在pages下面新建detials_page的文件件并在里面新建 ...