hdu 5802 Windows 10 贪贪贪
题意:把p变成q;升的时候每次只能升1,降的时候如果前一次是升或者停,那么下一次降从1开始,否则为前一次的两倍
官方题解:
您可能是正版Windows 10的受害者_ 直接贪心就好
比较直观的看法是使劲往下降,然后升回来
或者使劲往下降然后停顿然后再使劲往下降。。。
于是就能将问题变成一个子问题,然后dfs就好
需要注意的是由于按up键也可以打断连续向下的功效
所以应该记录停顿了几次,以后向上的时候用停顿补回来
/**************************************************************
Problem:hdu 5802
User: youmi
Language: C++
Result: Accepted
Time:312MS
Memory:1580K
****************************************************************/
//#pragma comment(linker, "/STACK:1024000000,1024000000")
//#include<bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#include <cmath>
#include <queue>
#include <deque>
#include <string>
#include <vector>
#define zeros(a) memset(a,0,sizeof(a))
#define ones(a) memset(a,-1,sizeof(a))
#define sc(a) scanf("%d",&a)
#define sc2(a,b) scanf("%d%d",&a,&b)
#define sc3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define scs(a) scanf("%s",a)
#define sclld(a) scanf("%I64d",&a)
#define pt(a) printf("%d\n",a)
#define ptlld(a) printf("%I64d\n",a)
#define rep(i,from,to) for(int i=from;i<=to;i++)
#define irep(i,to,from) for(int i=to;i>=from;i--)
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
#define lson (step<<1)
#define rson (lson+1)
#define eps 1e-6
#define oo 0x3fffffff
#define TEST cout<<"*************************"<<endl
const double pi=*atan(1.0); using namespace std;
typedef long long ll;
template <class T> inline void read(T &n)
{
char c; int flag = ;
for (c = getchar(); !(c >= '' && c <= '' || c == '-'); c = getchar()); if (c == '-') flag = -, n = ; else n = c - '';
for (c = getchar(); c >= '' && c <= ''; c = getchar()) n = n * + c - ''; n *= flag;
}
int Pow(int base, ll n, int mo)
{
if (n == ) return ;
if (n == ) return base % mo;
int tmp = Pow(base, n >> , mo);
tmp = (ll)tmp * tmp % mo;
if (n & ) tmp = (ll)tmp * base % mo;
return tmp;
}
//***************************
ll p,q;
const int maxn=+;
ll bit[];
void init()
{
bit[]=;
for(int i=;i<=;i++)
bit[i]=bit[i-]<<;
for(int i=;i<=;i++)
bit[i]-=;
}
ll ans;
int tot;
void dfs(int temp,int nn)//temp保存的是p和q的差值
{
if(temp==)
{
ans=Min(ans,nn);
return;
}
int res=nn;
int tt=lower_bound(bit,bit+,temp)-bit;//求出连续降的次数,bit[tt]是大于等于temp的,所以如果取bit[tt]会得到小于0的结果,这时候只能升
if(tot>abs(bit[tt]-temp))//如果停顿的次数大于要升的大小,那么直接取0就好了
ans=Min(ans,nn+tt);
else
ans=Min(ans,nn+tt+Min(q,abs(bit[tt]-temp)-tot));//还有就是要和q比较,如果bit[tt]-temp>q,那么会减到小于0,而最小是0
if(temp<bit[tt])//如果取bit[tt-1],也就是降到刚好比q大,这时候的操作就是减掉tt-1,然后停顿一下,并修改降了bit[tt-1]后的值
tt--;
res+=tt;
temp-=bit[tt];
if(temp)//tot表示停了几次
res+=,tot++;
dfs(temp,res);
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif
init();
int T_T;
scanf("%d",&T_T);
for(int kase=;kase<=T_T;kase++)
{
sclld(p);
sclld(q);
if(p<=q)
{
printf("%I64d\n",q-p);
continue;
}
ll temp=p-q;
ans=oo;
tot=;
dfs(temp,);
ptlld(ans);
}
}
hdu 5802 Windows 10 贪贪贪的更多相关文章
- 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)To ...
- hdu 5802 Windows 10 (dfs)
Windows 10 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total ...
- 2016暑假多校联合---Windows 10
2016暑假多校联合---Windows 10(HDU:5802) Problem Description Long long ago, there was an old monk living on ...
- hdu5802 Windows 10 贪心
Windows 10 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total ...
- 获取微软原版“Windows 10 推送器(GWX)” 卸载工具
背景: 随着Windows 10 免费更新的结束,针对之前提供推送通知的工具(以下简称GWX)来说使命已经结束,假设您还未将Windows 8.1 和Windows 7 更新到Windows 10 的 ...
- Windows 10 部署Enterprise Solution 5.5
Windows 10正式版发布以后,新操作系统带来了许多的变化.现在新购买的电脑安装的系统应该是Windows 10.与当初用户不习惯Windows 7,购买新电脑后第一个想做的事情就是重装成XP,估 ...
- 如何通过官方渠道为Windows 10 添加具有中国特色的字体
Windows 10的变化细节上个人认为要比Windows 8多很多,而且很多功能找到之后还是小惊喜,就是挺多好用的地方居然都不正经宣传一下,微软真是搞得悄悄地干活? 今天为大家介绍一下通过官方途径添 ...
- 如何修复Windows 10 Enterprise 在9月更新后图片全部由绘图板打开的情况
在进行了本月更新日的洗礼之后,企业版的Windows 10 突然发现无法好好的进行图片查看. 因为更新之前,各种图片都是使用“照片程序”打开的(这个是photos app),然后更新之后,这个app就 ...
随机推荐
- 线段树或树状数组---Flowers
题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=4325 Description As is known to all, the blooming tim ...
- 多准则决策模型-TOPSIS方法
多准则决策–Multiple Criteria Decision Making 多准则决策–Multiple Criteria Decision Making 多准则决策是指在具有相互冲突.不可共度的 ...
- [HTML5] 飞龙天惊-HTML5学习系列
飞龙天惊 cnblog URL:http://www.cnblogs.com/fly_dragon/ Html5 学习系列(一)认识HTML5 http://www.cnblogs.com/fly_d ...
- javascript数组浅谈3
前两节说了数组最基本的创建,队列方法,排序和一些操作方法,这节说说迭代和归并方法. every()方法 & some()方法 这两个方法会对数组中的每一项运行给定函数,然后返回一个布尔值,理解 ...
- English Training Material - 05
Could I leave a message? Language Checklist Telephoning (1) Introducing yourself Good morning, Arist ...
- Sharepoint学习笔记—习题系列--70-573习题解析 -(Q118-Q120)
Question 118You are creating a Business Connectivity Services (BCS) entity.You need to ensure that a ...
- C++ RTTI
一.定义:RTTI:Run Time Type Identification ,运行时类型识别:指程序能够使用基类的指针或引用来检索其所指对象的实际派生类型.二.使用方式:C++中有两个操作符提供RT ...
- 异步post请求之Block方法
#import "ViewController.h" #import "Header.h" @interface ViewController ()<NS ...
- UVa 111 - History Grading (by 最长公共子序列 )
History Grading Background Many problems in Computer Science involve maximizing some measure accor ...
- TCP & UDP 的区别
一.概念 ① TCP(Transmission Control Protocol 传输控制协议)是一种面向连接的.可靠的.基于字节流的传输层通信协议. “面向连接”就是在正式通信前必须要与对方建立起连 ...