codeforces 680D D. Bear and Tower of Cubes(dfs+贪心)
题目链接:
2 seconds
256 megabytes
standard input
standard output
Limak is a little polar bear. He plays by building towers from blocks. Every block is a cube with positive integer length of side. Limak has infinitely many blocks of each side length.
A block with side a has volume a3. A tower consisting of blocks with sides a1, a2, ..., ak has the total volume a13 + a23 + ... + ak3.
Limak is going to build a tower. First, he asks you to tell him a positive integer X — the required total volume of the tower. Then, Limak adds new blocks greedily, one by one. Each time he adds the biggest block such that the total volume doesn't exceed X.
Limak asks you to choose X not greater than m. Also, he wants to maximize the number of blocks in the tower at the end (however, he still behaves greedily). Secondarily, he wants to maximize X.
Can you help Limak? Find the maximum number of blocks his tower can have and the maximum X ≤ m that results this number of blocks.
The only line of the input contains one integer m (1 ≤ m ≤ 1015), meaning that Limak wants you to choose X between 1 and m, inclusive.
Print two integers — the maximum number of blocks in the tower and the maximum required total volume X, resulting in the maximum number of blocks.
48
9 42
6
6 6 题意: 给一个上限,现在要你求一个值,这个值是用最多的小正方体拼接起来的,而且体积和尽量大; 思路: 每次贪心的选取,每次选比它小的或者改变上限选下一个; AC代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <bits/stdc++.h>
#include <stack>
#include <map> using namespace std; #define For(i,j,n) for(int i=j;i<=n;i++)
#define mst(ss,b) memset(ss,b,sizeof(ss)); typedef long long LL; template<class T> void read(T&num) {
char CH; bool F=false;
for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
F && (num=-num);
}
int stk[70], tp;
template<class T> inline void print(T p) {
if(!p) { puts("0"); return; }
while(p) stk[++ tp] = p%10, p/=10;
while(tp) putchar(stk[tp--] + '0');
putchar('\n');
} const LL mod=1e9+7;
const double PI=acos(-1.0);
const int inf=1e9;
const int N=1e5+10;
const int maxn=1e3+20;
const double eps=1e-12; LL d[N];
pair<int,LL>ans;
int search(LL x)
{
int l=0,r=N-1;
while(l<=r)
{
int mid=(l+r)>>1;
if(d[mid]<=x)l=mid+1;
else r=mid-1;
}
return l-1;
}
int dfs(LL cur,LL temp,int num)
{
if(num>ans.first)ans.first=num,ans.second=temp;
else if(num==ans.first&&temp>ans.second)ans.second=temp; int x=search(cur);
if(x==0)return 0;
dfs(cur-d[x],temp+d[x],num+1);
dfs(d[x]-1-d[x-1],temp+d[x-1],num+1);
} int main()
{
LL m;
ans.first=0;ans.second=0;
read(m);
for(int i=1;i<N;i++)d[i]=(LL)i*i*i;
dfs(m,0,0);
cout<<ans.first<<" "<<ans.second<<endl;
return 0;
}
codeforces 680D D. Bear and Tower of Cubes(dfs+贪心)的更多相关文章
- 【19.05%】【codeforces 680D】Bear and Tower of Cubes
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 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 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】679 B. Bear and Tower of Cubes
[题目]B. Bear and Tower of Cubes [题意]有若干积木体积为1^3,2^3,...k^3,对于一个总体积X要求每次贪心地取<=X的最大积木拼上去(每个只能取一次)最后总 ...
- Bear and Tower of Cubes Codeforces - 680D
https://codeforces.com/contest/680/problem/D 一道2D,又是搞两个小时才搞出来...不过好在搞出来了 官方题解:可以证明对于m,设a是满足a^3<=m ...
- 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个面分别有它的颜色(用数字给出),现在想要将立方体堆成塔,并且上面的立方体的序号要小 ...
- 【32.89%】【codeforces 574D】Bear and Blocks
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
随机推荐
- object.Equals与object.ReferenceEquals方法
object.Equals方法表达的是语义判等,不一定是引用判等. object.ReferenceEquals方法是肯定是引用判等. 怎么实现一个对象的值语义的 Equals方法?实验. MyCla ...
- 公告板shader
Shader "Custom/LightPoint" { Properties { _MainTex ("Main Tex", 2D) = "whit ...
- 将navigationbar的translucent属性设为No后,子控制器视图整体下移问题
如果不将navigationbar.translucent = YES 会觉得颜色很浅,因为这是半透明状态 若navigationbar.translucent = NO,颜色问题解决,但是子控制器视 ...
- python 微信跳一跳和源码解读
刚好周末,想研究一下前阵子很火的微信跳一跳 下面进入正文. 本文适用对象为WIN10系统,安卓用户.目的在于让丝毫没有接触过Python的小伙伴都能成功运行,如果你恰好是这样的对象,那么跟着我开始操作 ...
- python基础-第九篇-9.2线程与多线程
单线程 import time beginTime = time.time() for a in range(10): print(a) time.sleep(1) shijian = time.ti ...
- centos修改mysql密码或者进入mysql后解决Access denied for user ''@'localhost' to database 'mysql错误
原因是MySQL的密码有问题 用mysql匿名用户可以进入数据库,但是看不见mysql数据库. 解决办法:具体操作步骤:关闭mysql:# service mysqld stop然后:# mysqld ...
- Nodejs课堂笔记-第二课 package.json的作用
本文由Vikings(http://www.cnblogs.com/vikings-blog/) 原创,转载请标明.谢谢! 上节课,我们打造了一下IDE工具-web storm的显示界面.至少现在回到 ...
- android ui篇 自己写界面
对于一些较为简单的界面则自己进行写. 在这里就需要了解xml文件中一些基本的属性以及android手机的知识. 一.目前手机屏幕像素密度基本有5种情况.(以下像素密度简称密度) 密度 ldpi mdp ...
- crontab定时任务(待补充)
cron是一个ubuntu下的后台进程,用来定期的执行一些任务 想让cron执行你指定的任务,首先就要编辑crontab文件.crontab是一个文本文件,用来存放你要运行的命令 第一种 vim /e ...
- yii 资料
https://github.com/forecho/awesome-yii2 会随时更新 链接:http://pan.baidu.com/s/1mgCKtUK 密码:t6t1 与<YII框架& ...