【CodeForces】679 B. Bear and Tower of Cubes
【题目】B. Bear and Tower of Cubes
【题意】有若干积木体积为1^3,2^3,...k^3,对于一个总体积X要求每次贪心地取<=X的最大积木拼上去(每个只能取一次)最后总体积恰好为X,求给定的1~m内使积木数量最大的X,相同取X较大者。m<=10^15。
【题解】对于一个给定的限制m,考虑最大那块积木的选择,设最大的<=m的积木是a^3。
1.取a^3,那么下次限制为m-a^3。
2.取(a-1)^3,那么下次限制为a^3-1-(a-1)^3。
3.取(a-2)^3,那么下次限制为(a-1)^3-1-(a-2)^3。
显然取(a-2)不如取(a-1)优,所以对于给定的限制m只需要考虑取a^3或(a-1)^3,然后对新的限制递归进行。
复杂度O(n^1/3)。
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
ll ansp=,ans=,m;
ll p(int x){return 1ll*x*x*x;}
void dfs(ll m,ll x,ll y){
if(m<=){if(x>ansp||(x==ansp&&y>ans))ansp=x,ans=y;return;}
int t=;
while(p(t+)<=m)t++;
dfs(m-p(t),x+,y+p(t));
if(t>)dfs(p(t)--p(t-),x+,y+p(t-));
}
int main(){
scanf("%lld",&m);
dfs(m,,);
printf("%lld %lld",ansp,ans);
return ;
}
自己的写法:通过尽量堆积小数字可以得到最大数量,然后从大到小将每个数尽量增大(通过全部扫描判断每个数字是否增大,n很小)。
【CodeForces】679 B. Bear and Tower of Cubes的更多相关文章
- 【CodeForces】679 A. Bear and Prime 100
[题目]A. Bear and Prime 100 [题意]有一数字x,每次可询问一个数字y是否x的因子,最后输出数字x是否素数,要求询问次数<=20. [题解]容易发现[2,100]范围内的非 ...
- 【CodeForces】790 C. Bear and Company 动态规划
[题目]C. Bear and Company [题意]给定大写字母字符串,交换相邻字符代价为1,求最小代价使得字符串不含"VK"子串.n<=75. [算法]动态规划 [题解 ...
- 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 ...
- 【Codeforces】Round #491 (Div. 2) 总结
[Codeforces]Round #491 (Div. 2) 总结 这次尴尬了,D题fst,E没有做出来.... 不过还好,rating只掉了30,总体来说比较不稳,下次加油 A:If at fir ...
- 【Codeforces】Round #488 (Div. 2) 总结
[Codeforces]Round #488 (Div. 2) 总结 比较僵硬的一场,还是手速不够,但是作为正式成为竞赛生的第一场比赛还是比较圆满的,起码没有FST,A掉ABCD,总排82,怒涨rat ...
- Codeforces 680D Bear and Tower of Cubes 贪心 DFS
链接 Codeforces 680D Bear and Tower of Cubes 题意 求一个不超过 \(m\) 的最大体积 \(X\), 每次选一个最大的 \(x\) 使得 \(x^3\) 不超 ...
- Codeforces 680D - Bear and Tower of Cubes
680D - Bear and Tower of Cubes 思路:dfs+贪心,设剩余的体积为res,存在a,使得a3 ≤ res,每次取边长为a的立方体或者边长为a-1的立方体(这时体积上限变成a ...
- 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 ...
- 【19.05%】【codeforces 680D】Bear and Tower of Cubes
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
随机推荐
- jQuery之offset,position
获取/设置标签的位置数据 * offset(): 相对页面左上角的坐标 * position(): 相对于父元素左上角的坐标. 需求: 1. 点击 btn1 打印 div1 相对于页面左上角的位置 打 ...
- DIH增量、定时导入并检索数据--转载
原文地址:http://www.ifunit.com/984/solr%E5%AD%A6%E4%B9%A0%EF%BC%88%E4%BA%94%EF%BC%89dih%E5%A2%9E%E9%87%8 ...
- BZOJ 2157 旅行(树链剖分码农题)
写了5KB,1发AC... 题意:给出一颗树,支持5种操作. 1.修改某条边的权值.2.将u到v的经过的边的权值取负.3.求u到v的经过的边的权值总和.4.求u到v的经过的边的权值最大值.5.求u到v ...
- day 03 字符串 for 循环
1.有变量量name = "aleX leNb" 完成如下操作: 1)移除 name 变量量对应的值两边的空格,并输出处理理结果 name = "aleX leNb&qu ...
- Authenticator及AuthenticationStrategy
Authenticator的职责是验证用户帐号,是Shiro API中身份验证核心的入口点: 如果验证成功,将返回AuthenticationInfo 验证信息:此信息中包含了身份及凭证:如果验证失败 ...
- [洛谷P5136]sequence
题目大意:有$T(T\leqslant10^5)$组询问,每次求$A_n(n\leqslant10^{18})$:$$A_n=\left\lceil\left(\dfrac{\sqrt5+1}2\ri ...
- Spring Batch @SpringBatchTest 注解
Spring Batch 提供了一些非常有用的工具类(例如 JobLauncherTestUtils 和 JobRepositoryTestUtils)和测试执行监听器(StepScopeTestEx ...
- php安装gd库
安装gd需要以下库: gd-2.0.33.tar.gz http://www.boutell.com/gd/ jpegsrc.v6b.tar.gz http://www.ijg.org/ libpng ...
- spark(二)
一.spark的提交模式 --master(standalone\YRAN\mesos) standalone:-client -cluster 如果我们用client模式去提交程序,我们在哪个地方 ...
- C++11新利器
C++11常用特性的使用经验总结 unordered_map可能用的会比较多 省的写哈希表了. 但是浪费空间