当前位置:网站首页>AcWing 1912. 里程表(枚举)
AcWing 1912. 里程表(枚举)
2022-06-12 10:49:00 【柃歌】
【题目描述】
约翰的奶牛正在公路上旅行。
他们汽车上的里程表显示的是整数里程值。
旅途开始时里程表显示的里程值为 X X X,旅途结束时里程表显示的里程值为 Y Y Y。
每当里程表显示“有趣的”数字(包括开始和结束时显示的数字)时,奶牛们就会发出愉快的叫声。
如果一个数除去前导零以外的所有数字中,除了一个数字不同以外,其他所有数字都是相同的,那么这个数就是“有趣的”。
例如,33323和110是有趣的,而9779和55555不是有趣的。
请帮助约翰计算奶牛们在旅途中发出叫声的次数。
【输入格式】
共一行,包含两个整数 X X X和 Y Y Y。
【输出格式】
输出奶牛们在旅途中发出叫声的次数。
【数据范围】
100 ≤ X ≤ Y ≤ 1 0 16 100≤X≤Y≤10^{16} 100≤X≤Y≤1016
【输入样例】
110 133
【输出样例】
13
【样例解释】
110 ∼ 133 110\sim 133 110∼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 110,112,113,114,115,116,117,118,119,121,122,131,133。
【分析】
观察到这个数据范围我们不能枚举 X ∼ Y X\sim Y X∼Y中的所有数然后分别判断是否为有趣数字,因此需要换一种角度,可以枚举所有的有趣数字,即满足位数为 3 ∼ 17 3\sim 17 3∼17且有且只有一位数字不同,其它数字均相同。对于枚举的每一个有趣数字,如果在 X ∼ Y X\sim Y X∼Y的范围中,则答案加一。
【代码】
#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++)//枚举数的位数
for (int j = 0; j < 10; j++)//枚举相同的数字是哪一个
for (int k = 0; k < 10; k++)//枚举唯一的那个不同的数
if (j != k)//两个数必须不同
for (int u = 0; u < i; u++)//枚举不同的数出现在哪个位置
{
string str(i, '0' + j);
str[u] = '0' + k;
if (str[0] != '0')//不能有前导零
{
LL num = stoll(str);
if (num >= x && num <= y) res++;
}
}
cout << res << endl;
return 0;
}
边栏推荐
- SOT23(Small Outline Transistor)
- Mobile terminal commissioning
- PHP string encryption and decryption
- Thinking about the cooperation process of Network Library -- Some Thoughts on reading brpc
- The solution of Lenovo notebook ThinkPad t440 WiFi dropping all the time
- 力扣(LeetCode)162. 寻找峰值(2022.06.11)
- How to play the 618 super cat games on Taobao? Here comes the introduction to the overall activities of the Super Cat Games
- PHP Apple purchase verification steps
- Zabbix 监控之LLD
- 2022-06-11:注意本文件中,graph不是邻接矩阵的含义,而是一个二部图。 在长度为N的邻接矩阵matrix中,所有的点有N个,matrix[i][j]
猜你喜欢

M-Arch(番外12)GD32L233评测-CAU加解密(捉弄下小编)

This and final keywords

AcWing 135. 最大子序和(前缀和 + 单调队列求定长区间最小值)

分布式存储探索

使用cpolar远程办公(2)

AcWing 128. 编辑器(对顶栈 实现序列内部指定位置高效修改)

Malicious code analysis practice - lab03-03 Exe basic dynamic analysis

Class. Forname connection MySQL driver keeps throwing classnotfoundexception exception solution

k58.第一章 基于kubeadm安装kubernetes v1.23 -- 集群部署

Leetcode2154. Multiply the found value by 2 (binary search)
随机推荐
Index query efficiency of MySQL
How to refund the pre-sale deposit of JD 618 in 2022? Can JD 618 deposit be refunded?
分布式存储探索
AcWing 132. 小组队列(队列模拟题)
NFT数字藏品的可验证性和稀缺性
FPGA-按键实验
PHP get (remote) large file method record
Is the acceptance standard a test case?
Assign a specified amount to a specified number of people at random
Binassii module - converting between binary and ASCII
IIS add MIME type
Leetcode 2169. Get operands of 0
FPGA开发——Hello_world例程
元宇宙链游与传统游戏的区别
Love and hate in the Jianghu
CTF freshman cup PHP deserialization question - EzPop
2022 Taobao 618 Super Cat Games introduction 618 super cat games playing skills
Common regular expressions
Common configuration commands for Cisco network device security management
模块8作业