Created
April 25, 2010 18:40
-
-
Save anonymous/378614 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| using namespace std; | |
| int x; | |
| int tbl[10][10]; | |
| int ten[10]; | |
| int deg[10]; | |
| void dfs(int); | |
| int main() { | |
| int m, n; | |
| while (cin >> m >> n) { | |
| if (m == n) { | |
| cout << m; | |
| } | |
| for (int i = 0; i < 10; i++) { | |
| ten[i] = 0; | |
| deg[i] = 0; | |
| for (int j = 0; j < 10; j++) { | |
| tbl[i][j] = 0; | |
| } | |
| } | |
| for (int i = m; i <= n; i++) { | |
| if (i < 10) { | |
| ten[i] = 1; | |
| } else { | |
| int a = i / 10; | |
| int b = i % 10; | |
| tbl[a][b] += 1; | |
| ten[a] = 0; | |
| ten[b] = 0; | |
| deg[a]++; | |
| deg[b]--; | |
| } | |
| } | |
| int max = 0, start = -1; | |
| for (int i = 0; i < 10; i++) { | |
| if (deg[i] > max) { | |
| start = i; | |
| max = deg[i]; | |
| } | |
| } | |
| x = start; | |
| dfs(start); | |
| for (int i = 1; i < 10; i++) { | |
| if (ten[i] == 1) { | |
| cout << i; | |
| } | |
| } | |
| cout << endl; | |
| } | |
| return 0; | |
| } | |
| void dfs(int s) { | |
| if (s == -1) { | |
| return; | |
| } else { | |
| cout << s; | |
| x = s; | |
| int flag = 1, max = 0, i = -1; | |
| for (int d = 30; d >= -30; d--) { | |
| for (int i = 0; i < 10; i++) { | |
| if (tbl[s][i] > 0 && deg[i] == d) { | |
| tbl[s][i]--; | |
| deg[s]++; | |
| deg[i]--; | |
| flag = 0; | |
| if (s != x) { | |
| cout << s; | |
| } | |
| d = 30; | |
| dfs(i); | |
| } | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment