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 ...
随机推荐
- redis 2
http://www.infoq.com/cn/articles/tq-redis-memory-usage-optimization-storage 在Ubuntu下安装reids redis-2. ...
- LoadRunner参数值定义-摘自一米阳光
深入解析LoadRunner下的参数化取值 熟悉LoadRunner的人,相信都会经常使用参数化功能,但是对于参数化的使用到底了解多少,就值得深思了.包括本人在内也是,每次在做压力测试的时候,基本 ...
- github的使用与问题
GIT密钥的生成步骤 一 .设置Git的user name和email: $ git config --global user.name "name" $ git config - ...
- ZUFE OJ 2145 05机关图
Description Ink最近得到了一张藏宝图,这张图上共有n个藏宝室,但因为年代久远藏宝图上的路已经模糊不清,于是Ink找到了智慧的Pseudo,Pseudo告诉Ink,这个宝藏中每两个藏宝室之 ...
- EasyuiAPI:菜单
一.LinkButton(按钮) 1.通过标签创建: <a id="btn" href="#" class="easyui-linkbutton ...
- arttemplate函数摘录
对artTemplate函数摘录,希望可以用到自己平时的工作中去 var toString = function (value, type) { if (typeof value !== 'strin ...
- reshape2 数据操作 数据融合 (melt)
前面一篇讲了cast,想必已经见识到了reshape2的强大,当然在使用cast时配合上melt这种强大的揉数据能力才能表现的淋漓尽致. 下面我们来看下,melt这个函数以及它的特点. melt(da ...
- Implementing a builder: Zero and Yield
原文地址:http://fsharpforfunandprofit.com/posts/computation-expressions-builder-part1/ 前面介绍了bind和continu ...
- tomcat下获取当前路径的url中含有空格解决方法
参考博文(http://www.360doc.com/content/11/1009/17/4602013_154657565.shtml) web项目发布到Tomcat之后,如果tomcat是安装在 ...
- ashx入侵
<%@ WebHandler Language="C#" Class="TextLd" %>using System;using System.Co ...