【CF679B】Theseus and labyrinth(数学,贪心)
题意:
给一个m<=10^15,每次都减最接近当前值的立方数
让你找一个不大于m的最大的数并且这个数是减法次数最多的数
思路:见http://blog.csdn.net/miracle_ma/article/details/52458715
开始想用贪心直接写
后面发现步数是对的,但使原数最大很难处理,因为各个i^3之间i的差不都<=1
于是用DFS处理
以下是大神题解:
考虑第一块取多少,最大的a3≤m
如果取a,还剩m−a3
取a−1的话,那肯定最大的X是a3−1,剩下a3−1−(a−1)3
如果取a−2的话,肯定没有a−1来的优,因为剩下的比取a−1剩下的要少
所以就是取a或者a−1,然后对于每次剩下的都可以这么考虑
如果你问,剩下x的时候,不是应该要取最大的a么
所以我们开头假设的X,不一定是最终的X
最后根据你取的,重新安排开头的X
比如这会剩x,然后取a−1,x当作了a3−1−(a−1)3
那么只要在最开始的时候X取小一点就行了
所以dfs的时候记录个数,还剩多少,∑a3
var f:array[..]of qword;
n,ans1,ans2:qword;
i:longint; function clac(x:qword):qword;
var l,r,mid,last:qword;
begin
l:=; r:=trunc(sqrt(x)); last:=l;
while l<=r do
begin
mid:=(l+r)>>;
if mid*mid<=x div mid then begin last:=mid; l:=mid+; end
else r:=mid-;
end;
exit(last);
end; procedure dfs(s1,k,s2:qword);
var p:qword;
begin
if s1= then
begin
if (k>ans1)or((k=ans1)and(s2>ans2)) then begin ans1:=k; ans2:=s2; end;
exit;
end;
p:=clac(s1);
dfs(s1-f[p],k+,s2+f[p]);
if p> then dfs(f[p]--f[p-],k+,s2+f[p-]);
end; begin
// assign(input,'1.in'); reset(input);
//assign(output,'1.out'); rewrite(output);
readln(n);
for i:= to do begin f[i]:=i; f[i]:=f[i]*f[i]*f[i]; end;
ans1:=; ans2:=;
dfs(n,,);
writeln(ans1,' ',ans2);
//close(input);
//close(output);
end.
【CF679B】Theseus and labyrinth(数学,贪心)的更多相关文章
- Codeforces Round #354 (Div. 2) D. Theseus and labyrinth bfs
D. Theseus and labyrinth 题目连接: http://www.codeforces.com/contest/676/problem/D Description Theseus h ...
- 【25.93%】【676D】Theseus and labyrinth
time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 洛谷3月月赛div2 题解(模拟+数学+贪心+数学)
由于本人太蒻了,div1的没有参加,胡乱写了写div2的代码就赶过来了. T1 苏联人 题目背景 题目名称是吸引你点进来的. 这是一道正常的题,和苏联没有任何关系. 题目描述 你在打 EE Round ...
- UVALive 7147 World Cup(数学+贪心)(2014 Asia Shanghai Regional Contest)
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&category=6 ...
- HDOJ 5073 Galaxy 数学 贪心
贪心: 保存连续的n-k个数,求最小的一段方差... .预处理O1算期望. .. Galaxy Time Limit: 2000/1000 MS (Java/Others) Memory Lim ...
- FZU 2144 Shooting Game(数学+贪心)
主要思路:求出蚊子到达球的时间区间(用方程得解),对区间做一个贪心的选择,选择尽可能多的区间有交集的区间段(结构体排序即可),然后计数. #include <cstdio> #includ ...
- hdu 3573(数学+贪心)
Buy Sticks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- hdu 5747(数学,贪心)
Aaronson Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total ...
- Codeforces Round #323 (Div. 2) C 无敌gcd 数学/贪心
C. GCD Table time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
随机推荐
- 课下作业04-2String的使用方法
1.动手动脑之String.equals()方法public class StringEquals { public static void main(String[] args) { String ...
- Java中 Character方法练习:字符串中英文字母个数 5435abc54abc3AHJ5 正则:matches("[a-zA-Z0-9]{1}")
package com.swift; public class String_Letter_Number_Test { public static void main(String[] args) { ...
- 解决cocos2dx 打包lua环境搭建问题( ImportError: No module named Cheetah.Template)
将c++ 封装成lua调用时,显示一下错误: PYTHON_BIN not defined, use current python. generating userconf.ini... Genera ...
- cocos2dx 3.x for lua "异步加载"实现过程
在lua中,cocos2dx 建立的栈只能被一个线程(主线程)访问,如果在c++建立子线程,然后通过c++调用lua回调函数实现异步加载就会报错. 如果试图通过c++子线程直接实现加载资源,返回一个布 ...
- 分割catalina.out 每天生成一个文件
1. touch xxx(文件名字).sh 2. vim xxx.sh 写入 ----------------------- #!/bin/sh cd `dirname $0`pwdd=`d ...
- Ansible的使用和模块化深入
Ansible配置 配置文件:/etc/ansible/ansible.cfg [default] 默认配置 inventory = /etc/ansible/hosts主机清单 library = ...
- centos7.4系统部署nodejs前端项目
1.安装nodejs运行环境 wget命令下载Node.js安装包,该安装包是编译好的文件,解压之后,在bin文件夹中就已存在node和npm,无需重复编译 wget https://nodejs.o ...
- 多线程辅助类之CyclicBarrier(四)
CyclicBarrier是一个线程辅助类,和<多线程辅助类之CountDownLatch(三)>功能类似,都可以实现一组线程的相互等待.要说不通点,那就是CyclicBarrier在释放 ...
- Can Japan stand up to US request to contain China?
From Global Times Two days before US President Donald Trump's visit to Japan, A fake news story caug ...
- Tomcat上传文件报错:returned a response status of 403 Forbidden
出现这样的错误是没有权限对服务器进行写操作.需要在这个项目所在的tomcat中配置可写操作即可: 在tomcat的web.xml添加下面代码: <init-param><param- ...