Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _USE_MATH_DEFINES
- #include<stdio.h>
- #include<iostream>
- #include<vector>
- #include<cmath>
- #include<algorithm>
- #include<map>
- #include<set>
- #include<sstream>
- #include<cstring>
- #include<numeric>
- #include<limits.h>
- using namespace std;
- set<int> to;
- int lenAns = 0;
- bool found(string cur) {
- bool f = false;
- for (int i = 0; i <= 9999; i++) {
- string c = "";
- int cs = i;
- while (cs > 0) {
- cs += cs % 10 + '0';
- cs /= 10;
- }
- if (c == "") {
- c += '0';
- }
- if (cur.find(c)) {
- if (to.count(i) != 0) {
- to.erase(i);
- f = true;
- }
- }
- }
- return f;
- }
- void go(string cur, int len) {
- if (to.size() == 0) {
- if (len < lenAns) {
- lenAns = len;
- printf("%s\n", cur);
- }
- return;
- }
- bool any = false;
- for (int i = 0; i < 10; i++) {
- if (found(cur)) {
- cur += ('0' + i);
- go(cur, len + 1);
- cur = cur.substr(0, cur.length() - 1);
- }
- }
- }
- int main() {
- #ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin);
- #endif
- freopen("output.txt", "w", stdout);
- for (int i = 0; i < 10; i++) {
- for (int i = 0; i <= 9999; i++) {
- to.insert(i);
- }
- to.erase(i);
- string s = "";
- s += i + '0';
- go(s, 1);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement