hdu_5802_Windows 10(贪心)
题目链接:hdu_5802_Windows 10
题意:
给你两个音量a,b,要让你将音量a变到音量b,up:每秒只能一次加1的音量,down:如果连续按x秒,那么就会减2x-1的音量
题解:
对于a<=b,直接输出a-b就行
对于a>b:
要考虑3种情况:
1. 直接连按x秒
2. 先up到2x-1,然后再按x秒
3. 先连按x秒,再up到b
#include<bits/stdc++.h>
using namespace std;
typedef long long ll; ll p[];
int t,a,b;
void init()
{
ll tp=;
p[]=;
for(int i=;i<=;i++)p[i]=tp+p[i-],tp*=;
} inline void up(int&a,int b){if(a>b)a=b;} int fuck()
{
if(b==)
{
int pos=lower_bound(p,p+,a)-p;
return pos+;
}
int cnt=,now=,ans=INT_MAX;
while(a!=b)
{
int cha=a-b,tmp,ti;
int pos=lower_bound(p,p+,cha)-p;
tmp=a-p[pos],tmp=tmp<?:tmp;
ti=b-tmp-cnt,ti=ti<?:ti;
up(ans,pos++now+ti+cnt);//2,3情况合并处理
if(p[pos]>cha)pos--;
a-=p[pos],now+=pos+;//第一种情况
if(a==b)
{
up(ans,now+cnt);
break;
}
cnt++;//停顿次数
}
return ans;
} int main()
{
init();
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&a,&b);
if(a<=b)printf("%d\n",b-a);
else printf("%d\n",fuck());
}
return ;
}
hdu_5802_Windows 10(贪心)的更多相关文章
- hdu5802 Windows 10 贪心
Windows 10 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total ...
- hdu-5802 Windows 10(贪心)
题目链接: Windows 10 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
- cf div2 236 D
D. Upgrading Array time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- 区间DP 洛谷P2858牛奶零食
题目链接 题意:你有n个货物从1-n依次排列,每天可以从两侧选一个出来卖,卖的价格是当天的天数乘该货物的初始价格,问这批货物卖完的最大价格 输入:第一行n,之后是n个货物的初始价值 这道题不能用贪心做 ...
- lintcode 刷题 by python 总结(1)
博主之前在学习 python 的数据结构与算法的基础知识,用的是<problem-solving-with-algorithms-and-data-structure-using-python& ...
- HDU 5802 Windows 10 (贪心+dfs)
Windows 10 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5802 Description Long long ago, there was ...
- 2017多校第10场 HDU 6178 Monkeys 贪心,或者DP
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6178 题意:给出一棵有n个节点的树,现在需要你把k只猴子放在节点上,每个节点最多放一只猴子,且要求每只 ...
- 2018.10.27 codeforces402D. Upgrading Array(数论+贪心)
传送门 唉我觉得这题数据范围1e5都能做啊... 居然只出了2000 考完听zxyzxyzxy说我的贪心可以卡但过了? 可能今天本来是0+10+00+10+00+10+0只是运气好T1T1T1骗了10 ...
- hdu 3697 10 福州 现场 H - Selecting courses 贪心 难度:0
Description A new Semester is coming and students are troubling for selecting courses. Students ...
随机推荐
- 如何占用你用户的时间 and 如何提高客户的满意度 。 待续
未来的商业竞争, 可能本质上是在争取客户的时间 嗯..有不定时, 未知的奖励,游戏行业就经常使用, 比如打怪掉装备, 不一定掉什么好东西, 让人充满了期待, 玛雅宝石, 有一定的概率... 觉得公司员 ...
- Struts2 stracture
- 二十六、oracle pl/sql 分页
一.无返回值的存储过程 古人云:欲速则不达,为了让大家伙比较容易接受分页过程编写,我还是从简单到复杂,循序渐进的给大家讲解.首先是掌握最简单的存储过程,无返回值的存储过程. 案例:现有一张表book, ...
- Xcode8注释有时会失效的解决方法
1.苹果开发解决了xcode ghost,而且Xcode8也取消了三方插件的功能,所以注释有时会失效,解决办法终端运行命令:sudo /usr/libexec/xpccachectl 回车 + 输 ...
- Sass与Compress实战:第五章
概要:第5章展示了Compass如何使你免去编写跨浏览器的CSS3的痛苦. 本章内容: ● 用Compass的CSS3模块创建跨浏览器的CSS3样式表 ● 在低版本IE中支持一些CSS3的特性 ● C ...
- WindowsAzure上把WebApp和WebService同时部署在一个WebRole中
注:本文为个人学习转载,原文地址:http://blog.csdn.net/zztfj/article/details/6740327 最近开发一个和WindowsAzure相关的应用,该应用还调用了 ...
- HttpModule的基本概念
注:本文为个人学习摘录,原文地址:http://www.cnblogs.com/stwyhm/archive/2006/08/09/471765.html HttpModule是如何工作的 当一个HT ...
- Marble 添加自定义Layer
#include <marble/MarbleWidget.h> #include <marble/MarbleMap.h> #include <marble/Marbl ...
- ElasticSearch(3)-原理
参考文档: http://learnes.net/distributed_crud/bulk_requests.html 一.分布式集群 1.1 空集群 单台机器,其中没有数据,也没有索引. 集群中一 ...
- css3部分属性兼容性别扭写法(因为很多我就叫他别扭了,希望全面早早支持css3吧)
/*圆角class,需要设置圆角的元素加上class名称*/ .roundedCorners{ -webkit-border-radius: 10px;/*webkit内核浏览器*/ -moz-bor ...