UVa 331 - Mapping the Swaps
来源:互联网 发布:程序框图软件 编辑:程序博客网 时间:2024/05/21 09:08
传送门UVa 331 - Mapping the Swaps
用冒泡法步骤肯定是最短的。
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int num[10], cnt, n;bool Judge();void DFS();int main(){ //freopen("input.txt", "r", stdin); int i, j, cases = 1; bool flag; while (scanf("%d", &n) && n) { flag = false; cnt = 0; for (i = 0; i < n; i++) scanf("%d", &num[i]); if (Judge()) //一开始如果就是整齐的,不用DFS了 flag = true; if (!flag) DFS(); printf("There are %d swap maps for input data set %d.\n", cnt, cases++); } return 0;}bool Judge(){ for (int i = 0; i < n - 1; i++) if (num[i] > num[i + 1]) return false; return true;}void DFS(){ for (int i = 0; i < n - 1; i++) if (num[i] > num[i + 1]) { swap(num[i], num[i + 1]); if (Judge()) cnt++; else DFS(); swap(num[i], num[i + 1]); }}
0 0
- uva 331 Mapping the Swaps
- uva 331 - Mapping the Swaps
- UVa 331 - Mapping the Swaps
- uva 331 - Mapping the Swaps
- UVa 331 - Mapping the Swaps
- UVA 331 - Mapping the Swaps
- UVa 331 - Mapping the Swaps
- UVA 331 Mapping the Swaps
- uva 331 Mapping the Swaps
- uva 331 Mapping the Swaps
- uva 331 Mapping the Swaps
- UVa:331 Mapping the Swaps
- UVa 331 - Mapping the Swaps
- UVa 331Mapping the Swaps
- uva 331 - Mapping the Swaps
- UVa 331 - Mapping the Swaps
- UVA 331 - Mapping the Swaps
- UVA - 331 Mapping the Swaps
- 轻量级DbHelper之Insert和Update方法
- node app.js不起作用的解决方法
- Asp.net 使用正则和网络编程抓取网页数据(实用)
- 布尔变量应该初始化为true还是false?
- What every programmer needs to know about game networking
- UVa 331 - Mapping the Swaps
- JDK JRE JVM
- [转]VisualStudio如何组织解决方案的目录结构
- android--context分析
- 动态二维数组的分配与释放
- STL——顺序容器使用总结
- Java中的阻塞队列ArrayBlockingQueue的使用
- 在Linux上安装Redmine与apache整合进行项目管理
- 学习Android之第八个小程序文件保存(Notification、AndroidTestCase)