当前位置:网站首页>AcWing 1912. Odometer (enumeration)
AcWing 1912. Odometer (enumeration)
2022-06-12 10:55:00 【Eurya song】
【 Title Description 】
John's cow is traveling on the road .
The odometer on their car shows the whole mileage .
At the beginning of the journey, the mileage displayed on the odometer is X X X, At the end of the trip, the mileage displayed on the odometer is Y Y Y.
Whenever the odometer shows “ amusing ” Numbers ( Including the numbers displayed at the beginning and end ) when , The cows will make a pleasant cry .
If a number is in all numbers except the leading zero , Except for a different number , All other numbers are the same , So this number is “ amusing ”.
for example ,33323 and 110 It's interesting. , and 9779 and 55555 Not interesting .
Please help John count the number of times the cows cry during the journey .
【 Input format 】
All in one line , Contains two integers X X X and Y Y Y.
【 Output format 】
Output the number of times the cows make calls during the journey .
【 Data range 】
100 ≤ X ≤ Y ≤ 1 0 16 100≤X≤Y≤10^{16} 100≤X≤Y≤1016
【 sample input 】
110 133
【 sample output 】
13
【 Sample explanation 】
110 ∼ 133 110\sim 133 110∼133 Of all the numbers between , Interesting numbers are :
110 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 121 , 122 , 131 , 133 110,112,113,114,115,116,117,118,119,121,122,131,133 110,112,113,114,115,116,117,118,119,121,122,131,133.
【 analysis 】
Observing this data range, we cannot enumerate X ∼ Y X\sim Y X∼Y And then determine whether it is an interesting number , So we need to change the angle , You can enumerate all the interesting numbers , That is, the number of digits to be satisfied is 3 ∼ 17 3\sim 17 3∼17 There is only one digit difference , Other figures are the same . For every interesting number of enumerations , If in X ∼ Y X\sim Y X∼Y In the range of , Add one to the answer .
【 Code 】
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
LL x, y;
int res;
int main()
{
cin >> x >> y;
for (int i = 3; i <= 17; i++)// Enumerator bits
for (int j = 0; j < 10; j++)// Enumerate which number is the same
for (int k = 0; k < 10; k++)// Enumerate the only different number
if (j != k)// The two numbers must be different
for (int u = 0; u < i; u++)// Enumerate where different numbers appear
{
string str(i, '0' + j);
str[u] = '0' + k;
if (str[0] != '0')// There can't be leading zeros
{
LL num = stoll(str);
if (num >= x && num <= y) res++;
}
}
cout << res << endl;
return 0;
}
边栏推荐
- 元宇宙系统搭建与构造
- 淺談調和形狀上下文特征HSC對3DSC的改進
- XML Parsing Error: mismatched tag. Expected
- The name of a great man
- M-Arch(番外10)GD32L233评测-SPI驱动DS1302
- Reverse analysis of Huawei housekeeper software [transfer]
- AcWing 41. Stack containing min function (monotone stack)
- Stream as a return value in WCF - who disposes of it- Stream as a return value in WCF - who disposes it?
- Vscode code debugging skills
- Vite Basics
猜你喜欢

Malicious code analysis practice -- using apatedns and inetsim to simulate network environment

Leetcode2154. Multiply the found value by 2 (binary search)

This and final keywords
![Reverse analysis of Huawei housekeeper software [transfer]](/img/85/7af372808e75f8791936c59918466f.jpg)
Reverse analysis of Huawei housekeeper software [transfer]

AcWing 135. Maximum subsequence sum (prefix sum + monotone queue to find the minimum value of fixed length interval)

B+ 树的简单认识

Malicious code analysis practice - lab06-01 exe~Lab06-04. Exe dynamic analysis

A hundred secrets and a few secrets - Caesar encryption

How the ArrayList collection implements ascending and descending order

SOT23(Small Outline Transistor)
随机推荐
Principle analysis of vite HMR
AI - face
JS open common application market
Redis keys in PHP
分布式存储探索
自然语言处理nlp 数据集下载地址
IIS add MIME type
Malicious code analysis practice - lab03-02 DLL analysis
Leetcdoe 2037. 使每位学生都有座位的最少移动次数(可以,一次过)
Get start date and end date for all quarters of the year
Immer source code reading
CTF freshman cup PHP deserialization question - EzPop
人脸识别pip 安装dlib库失败
Assign a specified amount to a specified number of people at random
卡鱼刺别再喝醋吞米饭了!教你2招,让鱼刺安全“跑出来”
Properties Chinese garbled code
The most detailed explanation of the top ten levels of sqli labs platform
Flex layout
A snare - Cookie spoofing
Malicious code analysis practice - lab03-03 Exe basic dynamic analysis