CodeForces 679B Bear and Tower of Cubes
$dfs$,贪心。
#pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<vector> #include<map> #include<set> #include<queue> #include<stack> #include<iostream> using namespace std; typedef long long LL; const double pi=acos(-1.0),eps=1e-6; void File() {freopen("D:\\in.txt","r",stdin);freopen("D:\\out.txt","w",stdout); } template <class T> inline void read(T &x) {char c=getchar(); x=0;while(!isdigit(c)) c=getchar();while(isdigit(c)) {x=x*10+c-'0'; c=getchar();} }LL n,ans2; int ans1;void dfs(LL x,int a1,LL a2) {if(a1>ans1) ans1=a1,ans2=a2;else if(a2==ans1) ans2=max(ans2,a2);if(x==0) return;LL L=1,R=100000,pos;while(L<=R){LL mid=(L+R)/2;if(mid*mid*mid<=x) pos=mid,L=mid+1;else R=mid-1;}dfs(x-pos*pos*pos,a1+1,a2+pos*pos*pos);if(pos*pos*pos-1-(pos-1)*(pos-1)*(pos-1)>=0)dfs(pos*pos*pos-1-(pos-1)*(pos-1)*(pos-1),a1+1,a2+(pos-1)*(pos-1)*(pos-1)); }int main() {scanf("%lld",&n);dfs(n,0,0);printf("%d %lld\n",ans1,ans2);return 0; }
转载于:https://www.cnblogs.com/zufezzt/p/5868653.html
CodeForces 679B Bear and Tower of Cubes相关推荐
- 【CF679B】Bear and Tower of Cubes
题意 对于一个数 x x x,每次贪心地找到不小于剩下的数的最大的正整数的立方,减去这个数,并重复直至变成 0 0 0,操作次数即为 x x x的贡献. 在 [ 1 , m ] [1,m] [1,m] ...
- Codeforces Gym 100269 Dwarf Tower (最短路)
题目连接: http://codeforces.com/gym/100269/attachments Description Little Vasya is playing a new game na ...
- Codeforces Round #702 C. Sum of Cubes
解法:暴力 题目大意:给定一个x,求是否存在两个数使得 a*a*a + b*b*b = x. 思路:如果用双层for枚举,数据量一定会导致超时.所以可以通过枚举a,同时通过已经知道的x,来求出b,这样 ...
- CodeForces 658C Bear and Forgotten Tree 3(构造)
题意:构造一棵树,有N个点,直径为d,深度为h 思路:首先构造一个长度为d的链,然后把其中一个距离边上为h的点变为根.然后我们就不停的在距离根为h上面的那一点不停的加点就好了,使得新加入的点的距离也为 ...
- Codeforces A - Bear and Prime 100(交互题)
A - Bear and Prime 100 思路:任何一个合数都可以写成2个以上质数的乘积.在2-100中,除了4,9,25,49外都可以写成两个以上不同质数的乘积. 所以打一个质数加这四个数的表: ...
- Codeforces 658D Bear and Polynomials【数学】
题目链接: http://codeforces.com/contest/658/problem/D 题意: 给定合法多项式,改变一项的系数,使得P(2)=0,问有多少种方法? 分析: 暴力求和然后依次 ...
- Codeforces——791A Bear and Big Brother
小声BB 又开始更新了,最近打游戏王DL,这个栏目会留一些上分的心得. 题干 time limit per test:1 second memory limit per test:256 megaby ...
- Codeforces A. Bear and Big Brother
...不行.这题之后.不做1000分以下的了.很耻辱 A. Bear and Big Brother time limit per test 1 second memory limit per tes ...
- codeforces 680A Bear and Five Cards
点击打开链接 A. Bear and Five Cards time limit per test 2 seconds memory limit per test 256 megabytes inpu ...
最新文章
- 部署通用基础设施, 满足顶级 SLA 要求
- html5 判断手机电脑,H5_0006:JS判断PC,平板,手机平台的方法
- vue代码怎么变成小程序_使用vue编写h5公众号跳转小程序的实现代码
- Pytorch中图像预处理相关函数
- JavaScript的arguments及其子对象
- 改变网页标签图片(favicon)
- 设计模式--装饰器模式
- java中解释命令_闲来无事可来了解下Java中Javadoc命令的用法
- 分布式缓存产品Redis和memcached比较区别(图)
- ActiveMQ常见操作
- fasta文件中序列的排序
- Tomcat 日志文件分割
- 我踩过的支付通道的“坑”(一)
- Biopython -- SeqIO
- OpenStack巴塞罗那峰会,比拼技术更比拼用户体验
- 水波纹特效怎么制作?这波水波纹特效拉动满满复古感
- 虚拟机复制镜像操作方法
- 【服务器数据恢复】某银行服务器磁盘阵列多块硬盘掉线的数据恢复案例
- 【SAP Hana】SAP HANA协同开发代码管理应用入门
- MVC用filter做权限过滤