Bear and Tower of Cubes Codeforces - 680D
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!=-&<.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的更多相关文章
- 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 ...
- 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】679 B. Bear and Tower of Cubes
[题目]B. Bear and Tower of Cubes [题意]有若干积木体积为1^3,2^3,...k^3,对于一个总体积X要求每次贪心地取<=X的最大积木拼上去(每个只能取一次)最后总 ...
- 【19.05%】【codeforces 680D】Bear and Tower of Cubes
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- CodeForces 679B(Bear and Tower of Cubes)
题意:Limak要垒一座由立方体垒成的塔.现有无穷多个不同棱长(a>=1)的立方体.要求:1.塔的体积为X(X<=m).2.在小于X的前提下,每次都选体积最大的砖块.3.在砖块数最多的前提 ...
- uva 10051 Tower of Cubes(DAG最长路)
题目连接:10051 - Tower of Cubes 题目大意:有n个正方体,从序号1~n, 对应的每个立方体的6个面分别有它的颜色(用数字给出),现在想要将立方体堆成塔,并且上面的立方体的序号要小 ...
- Anya and Cubes CodeForces - 525E (双端搜索)
大意: 给定$n$元素序列$a$, 可以任选不超过$k$个$a_i$变换为$a_i!$, 求变换后任选若干元素和为S的方案数. 分成两块暴搜, 复杂度$O(3^{\frac{n}{2}})$ #inc ...
随机推荐
- 编写按键驱动以及在framework层上报按键事件
平台信息:内核:linux3.10 系统:android6.0平台:RK3288 前言:本文主要实现的功能是在android系统中添加一个按键,在驱动层使用定时器,每隔1秒钟向上层发送按键实现,fra ...
- HDU2829 Lawrence —— 斜率优化DP
题目链接:https://vjudge.net/problem/HDU-2829 Lawrence Time Limit: 2000/1000 MS (Java/Others) Memory L ...
- hdu1052 田忌赛马 —— 贪心
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1052 错误代码: #include<stdio.h>//田忌赛马,错误版 #include ...
- js里=、== 和===有什么区别?
说明:该文章是转载后进行修改完善的,望大家有收获. =是赋值运算符,==是关系运算符; ===是全等运算符. ”==”与”===”是不同的,一个是判断值是否相等,一个是判断值及类型是否完全相等.第一个 ...
- BZOJ 1619 [Usaco2008 Nov]Guarding the Farm 保卫牧场:dfs【灌水】
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1619 题意: 给你一个n*m的地形图,位置(x,y)的海拔为h[x][y]. 一个山顶的定 ...
- UVA-10534 (LIS)
题意: 给定一个长为n的序列,求一个最长子序列,使得该序列的长度为2*k+1,前k+1个数严格递增,后k+1个数严格单调递减; 思路: 可以先求该序列最长单调递增和方向单调递增的最长序列,然后枚举那第 ...
- Java笔记(十)
正则表达式: 符合一定规则的表达式,用于专门操作字符串. 对QQ号码进行校验,要求:5-11位,0不能开头,只能是数字. public class Demo{ public static void m ...
- 「USACO16OPEN」「LuoguP3146」248(区间dp
题目描述 Bessie likes downloading games to play on her cell phone, even though she doesfind the small to ...
- bzoj 2006 [NOI2010]超级钢琴——ST表+堆
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2006 每个右端点的左端点在一个区间内:用堆记录端点位置.可选区间,按价值排序:拿出一个后也许 ...
- linux学习 三 redhat
1: 查看redhat版本号. 2: 防火墙中加入8080 查看防火墙状态,root用户登录,执行命令systemctl status firewalld 开启防火墙:systemctl star ...