音量减的时候,分两种,一种是减到大于目标M,另一种是减到小于M,停顿的时候可以减少最后往上加的次数,小于0的时候变成0

然后比一下这两种的最小值。

 /*--------------------------------------------------------------------------------------*/
#include <algorithm>
#include <iostream>
#include <cstring>
#include <ctype.h>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map> //debug function for a N*M array
#define debug_map(N,M,G) printf("\n");for(int i=0;i<(N);i++)\
{for(int j=;j<(M);j++){\
printf("%d",G[i][j]);}printf("\n");}
//debug function for int,float,double,etc.
#define debug_var(X) cout<<#X"="<<X<<endl;
#define LL long long
const int INF = 0x3f3f3f3f;
const int LLINF = 0x3f3f3f3f3f3f3f3f;
/*--------------------------------------------------------------------------------------*/
using namespace std; LL N,M,ans;
int T; LL sum(int x) {return (1LL<<x) - 1LL;} LL dfs(LL cur,LL cnt,int stop)
{
//printf("cur:%d cnt:%d\n",cur,cnt);
if(cur == M) return cnt;
int i = ;
while(cur-sum(i) > M) i++; if(cur -sum(i) == M ) return cnt + i;
LL up = M - max(0LL,cur-sum(i) );
LL res = i + max(0LL,up-stop);
return min(cnt+res , dfs(cur-sum(i-) , cnt + i,stop+));
} int main()
{
scanf("%d",&T);
while(T--)
{
ans = LLINF;
scanf("%I64d%I64d",&N,&M);
if(N <= M)
{
printf("%I64d\n",M-N);
continue;
} printf("%I64d\n",dfs(N,,));
}
}

HDU5802-windows 10-dfs+贪心的更多相关文章

  1. 多校6 1010 HDU5802 Windows 10 dfs

    // 多校6 1010 HDU5802 Windows 10 // 题意:从p到q有三种操作,要么往上升只能1步,要么往下降,如果连续往下降就是2^n, // 中途停顿或者向上,下次再降的时候从1开始 ...

  2. hdu5802 Windows 10 贪心

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

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

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

  4. hdu-5802 Windows 10(贪心)

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

  5. hdu 5802 Windows 10 (dfs)

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

  6. HDU 5802 Windows 10

    传送门 Windows 10 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)To ...

  7. hdu 5802 Windows 10 贪贪贪

    传送门:hdu 5802 Windows 10 题意:把p变成q:升的时候每次只能升1,降的时候如果前一次是升或者停,那么下一次降从1开始,否则为前一次的两倍 官方题解: 您可能是正版Windows ...

  8. 2016暑假多校联合---Windows 10

    2016暑假多校联合---Windows 10(HDU:5802) Problem Description Long long ago, there was an old monk living on ...

  9. windows 10开启bash on windows,配置sshd,部署hadoop

    1.安装Bash on Windows 这个参考官网步骤,很容易安装,https://msdn.microsoft.com/en-us/commandline/wsl/install_guide 安装 ...

  10. ICPC Asia Nanning 2017 I. Rake It In (DFS+贪心 或 对抗搜索+Alpha-Beta剪枝)

    题目链接:Rake It In 比赛链接:ICPC Asia Nanning 2017 Description The designers have come up with a new simple ...

随机推荐

  1. C# List中随机获取N个字符

    static void Main(string[] args) { List<string> strList = new List<string>(); ; i <= ; ...

  2. Mysql 高负载排查思路

    Mysql 高负载排查思路 发现问题 top命令 查看服务器负载,发现 mysql竟然百分之两百的cpu,引起Mysql 负载这么高的原因,估计是索引问题和某些变态SQL语句. 排查思路 1. 确定高 ...

  3. 数据结构--线段树--lazy延迟操作

    A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 53749   ...

  4. Socket常见错误

    一.简介 本文介绍 Socket 连接常见错误.   二.常见错误 1)ECONNABORTED 描述:"software caused connection abort",即&q ...

  5. hdu 1506

    题目中叫求一个最大的区域,则第i个矩形对应的面积是ave[i] = (r[i] – l[i] + 1) * a[i];l[i]表示以它这个高度所能到达的最左边的位置(最左一个高度不小于它的高度的位置) ...

  6. 百度地图Api进阶教程-点击生成和拖动标注4.html

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...

  7. MySQL常用技巧

    1.查看MySQL版本信息: 1,登上 mysql>status; 2,登上 mysql>select version(); 3,登上 mysql> select @@version ...

  8. 【嵌入式开发板】8月终极暑促迅为Cortex-a9四核入门开发板

    核心板参数 尺寸 50mm*60mm 高度 连同连接器在内0.26cm CPU Exynos4412,四核Cortex-A9,主频为1.4GHz-1.6GHz 内存 1GB 双通道 DDR3(2GB  ...

  9. 《致命接触》:人畜共患传染病的故事,SARS一章非常精彩,四星推荐

    讲人畜共患的传染病的故事:亨德拉.埃博拉.疟疾.SARS.Q热.鹦鹉热.莱姆病.艾滋病等.作者比较会讲故事,又熟悉病毒传播相关的各种学科的知识(病毒学.生态学,还有一些我没记住的相关小学科),能把相关 ...

  10. 【Android Demo】通过WebService获取今日天气情况

    因为本身是在搞.NET方面的东东,现在在学习Android,所以想实现Android通过WebService接口来获取数据,网上很多例子还有有问题的.参考:Android 通过WebService进行 ...