ans

062_lichangyi 2020-11-21 15:25:53 5 返回题目

#include <bits/stdc++.h> using namespace std; int x[1001]; int y[1001]; int a[20000000]; bool vis[10000]; int head, tail; void push(int x) { a[++tail] = x; } int front() { return a[head + 1]; } void pop() { head++; } int size() { return tail - head; } bool empty() { return head == tail; } int main() { int n, k, cnt = 0, mod, v; cin >> n; cin >> k; for (int i = 1; i <= k; i++) cin >> x[i] >> y[i]; push(n); vis[n] = 1; while (!empty()) { int f = front(); pop(); cnt++; int t = f; mod = 1; while (t) { v = t % 10; t /= 10; for (int i = 1; i <= k; i++) { if (v == x[i]) { int ne_n = f + (y[i] - x[i]) * mod; if (!vis[ne_n]) { push(ne_n); vis[ne_n] = 1; } } } mod *= 10; } } cout << cnt; return 0; }

{{ vote && vote.total.up }}

共 1 条回复

gongxue_wangyi

用 Markdown 会死吗?