UVA - 11925 Generating Permutations 推理
来源:互联网 发布:PHP怎么跳转页面 编辑:程序博客网 时间:2024/05/18 15:30
题目大意:这题的题目是错的,他的第二个操作是把最后一个调到第一个,然后输出时要逆序输出
解题思路:类似冒泡排序法。先如果第一个是n的话,就调后面的到前面来,然后进行比较,取最大的放前面,这下下一次n到前面的时候,n-1就在n的后面了。
#include<cstdio>#include<vector>#include<deque>#define maxn 310using namespace std;int num[maxn], n;deque<int> dq;vector<int> ans;bool judge() { for(int i = 1; i <= n; i++) if(dq[i - 1] != i) return false; return true;}int main() { while(scanf("%d", &n) == 1 && n) { dq.clear(); ans.clear(); int t; for(int i = 1; i <= n; i++) { scanf("%d", &t); dq.push_back(t); } int MAX = 2 * n * n; for(int i = 0; i <= MAX; i++) { int x = dq[0]; int y = dq[1]; if(x == 1 && judge()) { break; } if(x > y && x != n) { ans.push_back(1); swap(dq[0],dq[1]); } else { ans.push_back(2); t = dq.back(); dq.pop_back(); dq.push_front(t); } } for(int i = ans.size() - 1; i >= 0; i--) printf("%d", ans[i]); printf("\n"); } return 0;}
0 0
- UVA - 11925 Generating Permutations 推理
- UVa:11925 Generating Permutations
- UVa 11925 - Generating Permutations
- UVa 11925 Generating Permutations
- UVa - 11925 - Generating Permutations
- UVA 11925 Generating Permutations
- UVA 11925 - Generating Permutations
- UVA 11925(p254)----Generating Permutations
- UVa #11925 Generating Permutations (习题8-7)
- UVa 11925 - Generating Permutations(构造法)
- UVa 11925:Generating Permutations(构造)
- uva 11925——Generating Permutations
- UVA 11925 Generating Permutations 逆向思维
- Generating Permutations UVA
- 11925 - Generating Permutations
- 习题8-7 UVA - 11925 Generating Permutations 生成排列(构造)
- 生成排列 Generating Permutations
- UVa 10098 Generating Fast
- Integer 与 int
- insetDrawable
- 元素的创建,插入,替换和删除
- 读书笔记《Windows程序设计》
- poi 导入 Excel
- UVA - 11925 Generating Permutations 推理
- linux下ab网站压力测试命令
- 欢迎使用CSDN-markdown编辑器
- 获取class函数的封装
- -bash:whois:command not found
- Spark parquet merge metadata问题
- ECshop彻底去版权(同时适用于2.7.3)
- BOM的属性和方法
- 无领导小组讨论面试真题解析(七)—— 荒岛逃生记