题面

BZOJ
洛谷

题解

每次加上十进制下的\(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;
}

相关文章:

  • 2021-08-01
  • 2021-11-30
  • 2021-11-03
  • 2021-05-30
  • 2022-01-19
  • 2022-01-11
  • 2022-03-08
猜你喜欢
  • 2021-12-11
  • 2021-09-26
  • 2022-03-08
  • 2021-12-24
  • 2022-12-23
相关资源
相似解决方案