1361:产生数(Produce)

简介: 1361:产生数(Produce)

时间限制: 1000 ms         内存限制: 65536 KB

【题目描述】

给出一个整数n(n≤2000)和k个变换规则(k≤15)。规则:

① 1个数字可以变换成另1个数字;

② 规则中,右边的数字不能为零。

例如:n=234,k=2规则为

2 → 5

3 → 6

上面的整数234经过变换后可能产生出的整数为(包括原数)234,534,264,564共4种不同的产生数。

求经过任意次的变换(0次或多次),能产生出多少个不同的整数。仅要求输出不同整数个数。

【输入】

nkx1x2…xny1y2…yn

【输出】

格式为一个整数(满足条件的整数个数)。

【输入样例】

234

2

2 5

3 6

【输出样例】

4

1. #include<cstdio>
2. #include<iostream>
3. #include<vector>
4. using namespace std;
5. int n,k;
6. int a[16],b[16];
7. vector<int> que;
8. int book[10001];
9. int main()
10. {
11.   scanf("%d %d",&n,&k);
12.   for(int i=0;i<k;i++)
13.     scanf("%d %d",&a[i],&b[i]);
14.   book[n]=1;
15.   que.push_back(n);
16.   int head=0,tail=0;
17.   while(head<=tail){
18.     int x=que[head++];
19.     int y=x,mod=1;
20.     while(x>0){
21.       int tmp=x%10;
22.       x/=10;
23.       for(int i=0;i<k;i++)
24.         if(a[i]==tmp){
25.           int p=y-tmp*mod+b[i]*mod;
26.           if(book[p]==0){
27.             book[p]=1;que.push_back(p);tail++;
28.           } 
29.         }
30.       mod*=10;
31.     }
32.   }
33.   printf("%d\n",tail+1);
34.   return 0;
35. }


相关文章
|
1月前
|
消息中间件 中间件 Kafka
Kafka - TimeoutException: Expiring 1 record(s) for art-0:120001 ms has passed since batch creation
Kafka - TimeoutException: Expiring 1 record(s) for art-0:120001 ms has passed since batch creation
497 0
|
9月前
|
JavaScript 前端开发 开发工具
关于错误消息 RangeError - Maximum call stack size exceeded at XXX
关于错误消息 RangeError - Maximum call stack size exceeded at XXX
LeetCode 1342. 将数字变成 0 的操作次数 Number of Steps to Reduce a Number to Zero
LeetCode 1342. 将数字变成 0 的操作次数 Number of Steps to Reduce a Number to Zero
|
JavaScript Dubbo 小程序
还在用 System.currentTimeMillis() 统计代码耗时?太 Low 啦
还在用 System.currentTimeMillis() 统计代码耗时?太 Low 啦
【1136】A Delayed Palindrome (20分)
【1136】A Delayed Palindrome (20分) 【1136】A Delayed Palindrome (20分)
86 0
【1144】The Missing Number (20 分)
【1144】The Missing Number (20 分) 【1144】The Missing Number (20 分)
71 0
【1106】Lowest Price in Supply Chain (25 分)
【1106】Lowest Price in Supply Chain (25 分) 【1106】Lowest Price in Supply Chain (25 分)
78 0
Using 1 worker with 2048MB memory limit 异常
这里使用的是node 16版本,在家里电脑可以,但是公司电脑不行,不知道为啥 最后换了14版本,就可以了。
1897 0
Using 1 worker with 2048MB memory limit 异常
|
存储 缓存 固态存储
Long Story of Block - 1 Data Unit
计算、存储、网络构成了云计算的基本组件。Linux 中的 IO 栈主要分为 Filesystem 与 Block 两层,前者包括 VFS 与各种类型的文件系统(包括 Ext4、XFS 等),描述了数据的组织形式、提供管理数据的接口;而后者包括通用块层 (generic block layer) 与各种类型的块设备驱动(包括 SCSI、NVMe、Virtio 等),主要实现了数据在非易失性存储(HD
373 1
Long Story of Block - 1 Data Unit