680D - Bear and Tower of Cubes

思路:dfs+贪心,设剩余的体积为res,存在a,使得a≤ res,每次取边长为a的立方体或者边长为a-1的立方体(这时体积上限变成a-1)。

代码:

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mem(a,b) memset((a),(b),sizeof(a))
#define pil pair<int,ll>
#define mp make_pair
const int N=1e5+;
ll mm[N]; pil dfs(int cur,ll res,ll x)
{
//cout<<res<<endl;
if(res==)
{
//cout<<cur<<' '<<x<<endl;
return mp(cur,x);
}
int a=upper_bound(mm+,mm+N,res)-mm;
a--;
pil ans=dfs(cur+,res-mm[a],x+mm[a]);
if(a>)ans=max(ans,dfs(cur+,mm[a]--mm[a-],x+mm[a-]));
return ans;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie();
ll m;
cin>>m;
for(int i=;i<N;i++)mm[i]=(ll)i*i*i; int a=upper_bound(mm+,mm+N,m)-mm;
a--;
pil ans=dfs(,m-mm[a],mm[a]);
if(a>)ans=max(ans,dfs(,mm[a]--mm[a-],mm[a-]));
cout<<ans.first<<' '<<ans.second<<endl;
return ;
}

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

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

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

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

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

  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. Bear and Tower of Cubes Codeforces - 680D

    https://codeforces.com/contest/680/problem/D 一道2D,又是搞两个小时才搞出来...不过好在搞出来了 官方题解:可以证明对于m,设a是满足a^3<=m ...

  8. Codeforces 385C Bear and Prime Numbers

    题目链接:Codeforces 385C Bear and Prime Numbers 这题告诉我仅仅有询问没有更新通常是不用线段树的.或者说还有比线段树更简单的方法. 用一个sum数组记录前n项和, ...

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

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

随机推荐

  1. Testbench结构篇

    对于standalone的block的verification: 采用结构化的Testbench:Testcase与Harness,BFM分别分离,来提高系统的可重用性.如图是一个典型结构: 其中所有 ...

  2. 网站建设中常用的JS代码段落

    1.屏蔽左右键 这个不介绍了. <script language="JavaScript"> document.oncontextmenu=new Function(& ...

  3. animation-play-state

    animation-play-state: css: .play-state{ -webkit-animation:f1 2s 0.5s infinite linear forwards altern ...

  4. quartz-job实现定时任务配置

    使用quartz开源调度框架,写服务实现在一些指定场景发送特定短信,创建一个实现org.quartz.Job接口的java类.Job接口包含唯一的方法: public void execute(Job ...

  5. ant编译无法依赖rt.jar

    最近同事在用ant编译投产的时候报了一个错误: 程序包com.sun.org.apache.xml.internal.security.exceptions不存在 大致网上搜集了一下资源:具体原因是相 ...

  6. Linux基础命令---ln

    ln 为指定的目录或者文件创建链接,如果没有指定链接名,那么会创建一个和源文件名字一样的链接. 此命令的适用范围:RedHat.RHEL.Ubuntu.CentOS.SUSE.openSUSE.Fed ...

  7. php header utf8 插入header("Content-type: text/html; charset=utf-8");

    PHP文件插入header("Content-type: text/html; charset=utf-8"); 相当于页面里面的<meta http-equiv=" ...

  8. MySQL笔记(二)数据库对象的创建和管理

    学校用 sqlserver ,记录数据移植到 mysql 过程中的一些问题(对应数据类型,主键外键等). 索引: 查看数据的物理路径 查看表相关的信息(SHOW CREATE TABLE.DESC) ...

  9. troubleshooting-sqoop mysql导入hive 报:GC overhead limit exceeded

    Halting due to Out Of Memory Error...18/09/13 21:42:17 INFO mapreduce.Job: Task Id : attempt_1536756 ...

  10. Node.js读取文件内容

    原文链接:http://blog.csdn.net/zk437092645/article/details/9231787 Node.js读取文件内容包括同步和异步两种方式. 1.同步读取,调用的是r ...