当前位置:网站首页>Cf1036c class numbers solution
Cf1036c class numbers solution
2022-07-06 07:29:00 【q779】
CF1036C Classy Numbers Answer key
Topic link :CF1036C Classy Numbers
The question : Define a number as “ Good number ”, If and only if its decimal representation does not exceed 3 3 3 A digital 1 ∼ 9 1 \sim 9 1∼9
for instance : 4 , 200000 , 10203 4,200000,10203 4,200000,10203 yes “ Good number ”, However 4231 , 102306 , 7277420000 4231,102306,7277420000 4231,102306,7277420000 No
Given [ l , r ] [l,r] [l,r], Ask how many x x x bring l ≤ x ≤ r l \le x \le r l≤x≤r, And x x x yes “ Good number ”
Altogether T ( 1 ≤ T ≤ 1 0 4 ) T(1 \le T \le 10^{4}) T(1≤T≤104) Group data , For each inquiry , Output an integer on a line to represent the answer
1 ≤ l i ≤ r i ≤ 1 0 18 1 \le l_i \le r_i \le 10^{18} 1≤li≤ri≤1018
General figures dp It can be used to solve ∑ i = l r f ( i ) \sum _{i=l}^{r} f(i) ∑i=lrf(i) The problem of ,
among f ( i ) f(i) f(i) As with the i i i A function or determinant related to the digits of
This question is slightly distorted , Then we will naturally record the occurrence of figures
set up f i , j f_{i,j} fi,j It means full i i i digit , Yes j j j A non 0 0 0 position
Using memory search , See the code for details.
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iomanip>
using namespace std;
#define int long long
#define INF 0x3f3f3f3f3f3f3f3f
#define N (int)()
int num[25],f[25][5];
// u Indicates the current number of digits ,st Represents the current j,limit Indicates whether there is a high limit
int dfs(int u,int st,bool limit)
{
if(!u)return 1;
if(!limit&&f[u][st]!=INF)
return f[u][st]; // Memorize
int up=limit?num[u]:9,ans=0;
for(int i=0; i<=up; i++)
{
if(!i)ans+=dfs(u-1,st,limit&&num[u]==i);
else if(st!=3)ans+=dfs(u-1,st+1,limit&&num[u]==i);
}
if(!limit) f[u][st]=ans; // Just record what has no upper limit
return ans;
}
int solve(int x)
{
int len=0;
while(x>0)
{
num[++len]=x%10;
x/=10;
}
return dfs(len,0,1);
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
// freopen("check.in","r",stdin);
// freopen("check.out","w",stdout);
memset(f,0x3f,sizeof(f));
int Q;cin >> Q;
while(Q--)
{
int l,r;
cin >> l >> r;
cout << solve(r)-solve(l-1) << '\n';
}
return 0;
}
reference
[1] https://www.luogu.com.cn/blog/rated/solution-cf1036c
Reprint please explain the source
边栏推荐
- Is the super browser a fingerprint browser? How to choose a good super browser?
- The differences and advantages and disadvantages between cookies, seeion and token
- Chrome view page FPS
- Solution to the problem of breakthrough in OWASP juice shop shooting range
- The way to learn go (I) the basic introduction of go to the first HelloWorld
- 【mysql学习笔记30】锁(非教程)
- LeetCode Algorithm 2181. Merge nodes between zero
- word中把带有某个符号的行全部选中,更改为标题
- TS类型体操 之 字符串的妙用
- TypeScript 函数定义
猜你喜欢
TS 类型体操 之 extends,Equal,Alike 使用场景和实现对比
![[MySQL learning notes 30] lock (non tutorial)](/img/9b/1e27575d83ff40bebde118b925f609.png)
[MySQL learning notes 30] lock (non tutorial)

杰理之AD 系列 MIDI 功能说明【篇】

1091: two or three things in childhood (multi instance test)

JDBC学习笔记

(4) Web security | penetration testing | network security web site source code and related analysis

Do you really think binary search is easy
![If Jerry's Bluetooth device wants to send data to the mobile phone, the mobile phone needs to open the notify channel first [article]](/img/d6/92ad1c6f84415de6ab0dfd16cd6073.png)
If Jerry's Bluetooth device wants to send data to the mobile phone, the mobile phone needs to open the notify channel first [article]

How to delete all the words before or after a symbol in word

Crawling exercise: Notice of crawling Henan Agricultural University
随机推荐
合规、高效,加快药企数字化转型,全新打造药企文档资源中心
Jerry's general penetration test - do data transmission with app Communication [article]
C - Inheritance - polymorphism - virtual function member (lower)
[MySQL learning notes 32] mvcc
Typescript interface and the use of generics
word中把帶有某個符號的行全部選中,更改為標題
chrome查看页面fps
超级浏览器是指纹浏览器吗?怎样选择一款好的超级浏览器?
Typescript function definition
1091: two or three things in childhood (multi instance test)
Markdown 中设置图片图注
Structure summary of SystemVerilog integrable model
学go之路(二)基本类型及变量、常量
2022年Instagram运营小技巧简单讲解
Go learning -- implementing generics based on reflection and empty interfaces
jmeter性能测试步骤实战教程
Crawling exercise: Notice of crawling Henan Agricultural University
[window] when the Microsoft Store is deleted locally, how to reinstall it in three steps
Seriously recommend several machine learning official account
Redis builds clusters