码迷,mamicode.com
首页 > 其他好文 > 详细

dfs打表 C. Classy Numbers

时间:2019-01-22 13:15:12      阅读:202      评论:0      收藏:0      [点我收藏+]

标签:clipboard   eve   positive   题意   red   end   while   main   nes   

C. Classy Numbers

C. Classy Numbers
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Let‘s call some positive integer classy if its decimal representation contains no more than 33 non-zero digits. For example, numbers 44, 200000200000, 1020310203 are classy and numbers 42314231, 102306102306, 72774200007277420000 are not.

You are given a segment [L;R][L;R]. Count the number of classy integers xx such that LxRL≤x≤R.

Each testcase contains several segments, for each of them you are required to solve the problem separately.

Input

The first line contains a single integer TT (1T1041≤T≤104) — the number of segments in a testcase.

Each of the next TT lines contains two integers LiLi and RiRi (1LiRi10181≤Li≤Ri≤1018).

Output

Print TT lines — the ii-th line should contain the number of classy integers on a segment [Li;Ri][Li;Ri].

/***********************************************/
ll a,b,n;
vector<ll>V;

void dfs(ll x,int oo,int len)
{
	V.push_back(x);
	if(len==18) return ;
	dfs(x*10,oo,len+1);
	if(oo<3)
	for(int i=1;i<=9;i++) dfs(x*10+i,oo+1,len+1);
}

int main() 
{
	for(ll i=1;i<=9;i++) {
		dfs(i,1,1);
	}
	V.push_back(1e18);
	sort(V.begin(),V.end());
    scl(n);
    while(n--)
    {
    	ll ans=0;
    	scl2(a,b);
		ll l=lower_bound(V.begin(),V.end(),a)-V.begin();
		ll r=upper_bound(V.begin(),V.end(),b)-V.begin();
		cout<<r-l<<endl;
	}
    return 0;
}

  

dfs打表 C. Classy Numbers

标签:clipboard   eve   positive   题意   red   end   while   main   nes   

原文地址:https://www.cnblogs.com/liuyongliu/p/10303173.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!