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. webform中实现SQL Sever2008数据库数据分页查询

    1 分页     1.1         数据库中存储过程             已知 当前页  pageIndex  页容量 pageSize             求  总页数 pageCou ...

  2. 基于Jquery的XML解析器,返回定制的HTML

    依据HTML模板返回解析的XML 依赖jQuery 1.4​1. [代码]基于Jquery的xml解析器并返回定制的HTML     /** *  jQuery插件 *  Author: pureco ...

  3. map的详细用法 (转

    map的详细用法: map是STL的一个关联容器,它提供一对一(其中第一个可以称为关键字,每个关键字只能在map中出现一次,第二个可能称为该关键字的值)的数据处理能 力,由于这个特性,它完成有可能在我 ...

  4. C#评分小系统练习

    一个经理类 using System; using System.Collections.Generic; using System.Linq; using System.Text; using Sy ...

  5. Python模块:os

    OS模块常用用法: os.name() #判断当前使用的系统环境,windows则返回 ‘nt’,Linux则返回‘posix’ os.getcwd() #显示当前目录 os.listdir() #以 ...

  6. Preface Numbering

    链接 分析:先打表需要用到的罗马数字,然后暴力转换,最后统计一下即可 /* PROB:preface ID:wanghan LANG:C++ */ #include "iostream&qu ...

  7. 自己实现c++中string 类

    class String { public: String(const char *str = NULL);// 普通构造函数 String(const String &other);// 拷 ...

  8. Azure AD (6) 停止Azure AD Connect Sync同步,并删除自定义域名

    <Windows Azure Platform 系列文章目录> 如果你已经了解了我之前写的文章:Azure AD (5) 在单一目录下,使用Azure AD单点登录 应该对使用Azure ...

  9. HDU2087(KMP入门题)

    剪花布条 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  10. py-day1简单使用方法及语法使用详解

    一.python入门 1.python的标准格式 创建python文件以.py结尾 如:vi hello.py #!/usr/bin/env python #-*- coding:utf-8 -*- ...