POJ 1833 排序 解题报告
2011-01-09 22:21
316 查看
晕。没想到用cin,cout的效率这么低,而一定要改用scanf和printf。另外,还一定要用C++而不能用G++才不会TLE。
用C++ STL的next_permutation很简单。
用C++ STL的next_permutation很简单。
#include <algorithm> #include <cstdio> using namespace std; /*通过int数组读入序列,而不使用string。 *因为,如果遇到两位数,三位数,则很难将它们 *看成一个整体了。 */ int arr[1024]; int main() { int nCases; scanf("%d", &nCases); for(int i = 0; i < nCases; i++) { int n, k; scanf("%d%d", &n, &k); for(int j = 0; j < n; j++) { scanf("%d", &arr[j]); } int count = 0; while(count != k) { /*next_permutation实在强大,它也可以取int型数组的下一个排列。 *若到达了最后一个,则自动返回第一个元素。 */ next_permutation(arr, arr + n); count++; } for(int j = 0; j < n; j++) { printf("%d ", arr[j]); } printf("/n"); } return 0; }
相关文章推荐
- 解题报告:POJ_1833 排序
- POJ 1833 排列 解题报告
- POJ 1007(无序度 排序) 解题报告
- POJ 1007(无序度 排序) 解题报告
- POJ 1094 变量排序 解题报告
- poj2388解题报告(排序)
- POJ-1833-排列 解题报告
- (解题报告)POJ3664---Election Time---用结构体实现两组相关联数据的排序问题
- poj解题报告——1035
- POJ 1308 Is It A Tree? 解题报告
- poj解题报告——3080
- poj2312解题报告
- POJ 2533 Longest Ordered Subsequence 解题报告
- POJ 1047——解题报告
- poj_1068_Parencodings_解题报告
- Poj_3744 解题报告
- POJ 2892解题报告
- poj解题报告——1730
- 解题报告:POJ_1703Find them, Catch them 并查集
- POJ1068 Parencodings 解题报告