题目链接: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(贪心)的更多相关文章

  1. hdu5802 Windows 10 贪心

    Windows 10 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total ...

  2. hdu-5802 Windows 10(贪心)

    题目链接: Windows 10 Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others ...

  3. cf div2 236 D

    D. Upgrading Array time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  4. 区间DP 洛谷P2858牛奶零食

    题目链接 题意:你有n个货物从1-n依次排列,每天可以从两侧选一个出来卖,卖的价格是当天的天数乘该货物的初始价格,问这批货物卖完的最大价格 输入:第一行n,之后是n个货物的初始价值 这道题不能用贪心做 ...

  5. lintcode 刷题 by python 总结(1)

    博主之前在学习 python 的数据结构与算法的基础知识,用的是<problem-solving-with-algorithms-and-data-structure-using-python& ...

  6. HDU 5802 Windows 10 (贪心+dfs)

    Windows 10 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5802 Description Long long ago, there was ...

  7. 2017多校第10场 HDU 6178 Monkeys 贪心,或者DP

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6178 题意:给出一棵有n个节点的树,现在需要你把k只猴子放在节点上,每个节点最多放一只猴子,且要求每只 ...

  8. 2018.10.27 codeforces402D. Upgrading Array(数论+贪心)

    传送门 唉我觉得这题数据范围1e5都能做啊... 居然只出了2000 考完听zxyzxyzxy说我的贪心可以卡但过了? 可能今天本来是0+10+00+10+00+10+0只是运气好T1T1T1骗了10 ...

  9. hdu 3697 10 福州 现场 H - Selecting courses 贪心 难度:0

    Description     A new Semester is coming and students are troubling for selecting courses. Students ...

随机推荐

  1. box-size

    <style> *{ margin:0; padding:0; list-style:none; font-family:"\5FAE\8F6F\96C5\9ED1"; ...

  2. java学习 (2)xml操作 SAX(增、删、改、查)

    sax是事件驱动的,sax是一种推模式 SAX常用事件: startDocument()----文档开始事件 startElement()-----元素开始事件 charElement()----文本 ...

  3. U盘安装VMware ESXi 6.0

    准备工作 在vmware官网注册,并获取ESXi 6.0 ISO Image: 下载UNetbootin: 容量1GB或以上的U盘,将其格式化. U盘制作 打开UNetbootin,如下图设置,文件路 ...

  4. webAppRootKey

    web.xml中webAppRootKey ------------------------------------------------------------------------------ ...

  5. DEV TdxLayoutGroup设置tab

    TdxLayoutGroup 属性的 LayoutDirection :ldvertical,ldtabbed(显示tab页),ldhorizontal

  6. SQL 范式(转载)

    装载于"http://www.cnblogs.com/KissKnife/ 理论性的东西,往往容易把人人都看得懂的东西写成连鬼都看不懂,近似于主任医生开的药方.从前学范式的时候,把书中得概念 ...

  7. OGG强制停止进程

    1.异常现象[oracle@localhost ~]$ ggsci Oracle GoldenGate Command Interpreter for OracleVersion 11.1.1.0.0 ...

  8. openstack私有云布署实践【14.2 登录页dashboard-controller(办公网环境)】

    这一小节基本配置相同,但留意以下紫色部份的配置,当初为了管理方便,我们让办公网openstack的dashboard的登录桥接了科兴的dashboard,由此统一dashboard界面的登录地址   ...

  9. 第一章 flume架构介绍

    1.flume概念介绍 1.1 常见的分布式日志收集系统                             Scribe是facebook开源的日志收集系统,在facebook内部已经得到大量的 ...

  10. IOS开发小技巧,知识点

    1.IOS模拟器第一次打开需要进入“设置”中关掉"Auto-Capitalization"选项. 2.NSInteger转化 NSString类型: [NSString strin ...