Download uva_cpp_clean/10017/10017-9.cpp from slayone/uva_spoj_raw: direct link, hf CLI and curl.
- Browser
- Download file 1.19 kB
-
https://huggingface.co/datasets/slayone/uva_spoj_raw/resolve/main/uva_cpp_clean/10017/10017-9.cpp
- Command line
-
hf download hf://datasets/slayone/uva_spoj_raw/uva_cpp_clean/10017/10017-9.cpp
-
curl -L -o 10017-9.cpp https://huggingface.co/datasets/slayone/uva_spoj_raw/resolve/main/uva_cpp_clean/10017/10017-9.cpp
1.19 kB
| using namespace std; | |
| int tc, n, m; | |
| deque <int> Tower[5]; | |
| void printTower(int id){ | |
| printf("%c=>", id + 'A'); | |
| if(Tower[id].empty()){ | |
| putchar('\n'); | |
| return; | |
| } | |
| printf(" "); | |
| for(int it = 0, sz = Tower[id].size() - 1; it <= sz; it++) | |
| printf( it != sz ? "%d " : "%d\n", Tower[id][it]); | |
| } | |
| void printDisks(){ | |
| putchar('\n'); | |
| printTower(0); | |
| printTower(1); | |
| printTower(2); | |
| } | |
| void backtrack(int disks, int source, int destination, int intermediate){ | |
| if( m == 0 ) return; | |
| if( disks == 1 ){ | |
| m--; | |
| Tower[destination].push_back(Tower[source].back()); | |
| Tower[source].pop_back(); | |
| printDisks(); | |
| return; | |
| } | |
| backtrack(disks - 1, source, intermediate, destination); | |
| backtrack(1, source, destination, intermediate); | |
| backtrack(disks - 1, intermediate, destination, source); | |
| } | |
| int main(){ | |
| while(scanf("%d %d", &n, &m), n | m){ | |
| for(int it = 0; it < 3; it++) Tower[it].clear(); | |
| for(int disk = n; disk >= 1; disk--) | |
| Tower[0].push_back(disk); | |
| printf("Problem #%d\n", ++tc); | |
| printDisks(); | |
| backtrack(n, 0, 2, 1); | |
| putchar('\n'); | |
| } | |
| return(0); | |
| } | |