【BZOJ4029】[HEOI2015]定价(贪心)
【BZOJ4029】[HEOI2015]定价(贪心)
题面
题解
每次加上十进制下的\(lowbit\)就行了???
#include<iostream>
#include<cstdio>
using namespace std;
inline int read()
{
int x=0;bool t=false;char ch=getchar();
while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
if(ch=='-')t=true,ch=getchar();
while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
return t?-x:x;
}
int lowbit(int x)
{
for(int i=1;;i*=10)
if(x%10)return i;
else x/=10;
}
int calc(int x)
{
while(x%10==0)x/=10;
int l=0;if(x%10==5)l-=1;
while(x)l+=2,x/=10;
return l;
}
int main()
{
int T=read();
while(T--)
{
int l=read(),r=read(),ans=1e9,val=l;
while(l<=r)
{
int x=calc(l);
if(ans>x)ans=x,val=l;
l+=lowbit(l);
}
printf("%d\n",val);
}
return 0;
}