HDU5802-windows 10-dfs+贪心
音量减的时候,分两种,一种是减到大于目标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+贪心的更多相关文章
- 多校6 1010 HDU5802 Windows 10 dfs
// 多校6 1010 HDU5802 Windows 10 // 题意:从p到q有三种操作,要么往上升只能1步,要么往下降,如果连续往下降就是2^n, // 中途停顿或者向上,下次再降的时候从1开始 ...
- hdu5802 Windows 10 贪心
Windows 10 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total ...
- HDU 5802 Windows 10 (贪心+dfs)
Windows 10 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5802 Description Long long ago, there was ...
- hdu-5802 Windows 10(贪心)
题目链接: Windows 10 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
- hdu 5802 Windows 10 (dfs)
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)To ...
- hdu 5802 Windows 10 贪贪贪
传送门:hdu 5802 Windows 10 题意:把p变成q:升的时候每次只能升1,降的时候如果前一次是升或者停,那么下一次降从1开始,否则为前一次的两倍 官方题解: 您可能是正版Windows ...
- 2016暑假多校联合---Windows 10
2016暑假多校联合---Windows 10(HDU:5802) Problem Description Long long ago, there was an old monk living on ...
- windows 10开启bash on windows,配置sshd,部署hadoop
1.安装Bash on Windows 这个参考官网步骤,很容易安装,https://msdn.microsoft.com/en-us/commandline/wsl/install_guide 安装 ...
- 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 ...
随机推荐
- 我已看过的TVB剧集目录(陆续更新)
2016年度TVB剧集 <一屋老友记> 主演:欧阳震华,胡定欣,滕丽名,罗兰 <纯熟意外> 主演:吴启华,蔡思贝,李施嬅,黎诺懿 <廉政行动2016> 主演:陈展鹏 ...
- CentOS下如何完全卸载MySQL?卸载自带的mysql
CentOS下如何完全卸载MySQL?解决卸载不干净的问题 系统:CentOS 6.5,MySQL:MySql 5.6 这里主要解决使用rpm安装的卸载问题,安装方法见:CentOS安装mysql*. ...
- Memcache笔记03-php操作Memcached
通过php程序操作Memcached服务几种形式 Memcache 扩展 Memcached 扩展 Socket套接字操作 memcached-client.php(函数) 对于php扩展来说,dan ...
- Node.js(2)-protobuf zeromq gzip
1.Node.Js环境准备 在win8 + vs.net 2012 环境下调试了很长时间没搞定安装编译问题,重装系统测试了2套环境,解决了编译问题: 1)Win8.1 + vs.net 2013 2) ...
- Effective Java 62 Document all exceptions thrown by each method
Principle Always declare checked exceptions individually, and document precisely the conditions unde ...
- Group By Count不能显示0的问题
问题: 如对表: /*==================================================== id |score |grade ------------------- ...
- keepalived初探
keepalived起初是为LVS设计的,专门用来监控LVS集群系统中各个real server的健康状况的,后来又在其中实现了VRRP协议,VRRP即virtual router redundanc ...
- 你真的说的清楚ArrayList和LinkedList的区别吗
参见java面试的程序员,十有八九会遇到ArrayList和LinkedList的区别?相信很多看到这个问题的人,都能回答个一二.但是,真正搞清楚的话,还得花费一番功夫. 下面我从4个方面来谈谈这个问 ...
- Web Service和WCF的到底有什么区别
[1]Web Service:严格来说是行业标准,也就是Web Service 规范,也称作WS-*规范,既不是框架,也不是技术. 它有一套完成的规范体系标准,而且在持续不断的更新完善中. 它使用XM ...
- MyEclipse下创建的项目导入到Eclipse中详细的图文配置方法
一.情景再现. 有些人比较喜欢用Myeclipse开发,有些人却比较喜欢用eclipse开发.但是其中有一个问题,Myeclipse里面的项目导入的时候出现了一个小小的问题. 如下: 二.说明问题 导 ...