UVA 120 煎饼堆
2012-09-01 10:06
204 查看
有点类似quick sort 但又感觉不太一样,贪心
每次从数组里面找到最大元素下标,如果在最顶层,则直接翻到当前最下层
否则先翻转到最上层,再翻转到最下层。
参考:/article/5198183.html
我喜欢STL,很符合我口味,用了泛型算法reverse(),Max_element(),还用了deque,非常好
每次从数组里面找到最大元素下标,如果在最顶层,则直接翻到当前最下层
否则先翻转到最上层,再翻转到最下层。
参考:/article/5198183.html
我喜欢STL,很符合我口味,用了泛型算法reverse(),Max_element(),还用了deque,非常好
#include <iostream> #include <sstream> #include <cstdio> #include <cstring> #include <cmath> #include <string> #include <vector> #include <set> #include <cctype> #include <algorithm> #include <cmath> #include <deque> using namespace std; /// #define INF 0xffffff7 #define MAXN 200 /// vector<string> num; deque<int> Stack; int main() { /// int i, j; string line; while (getline(cin, line)) { cout << line << endl; num.clear(); Stack.clear(); istringstream stream(line); int tempNum; while (stream >> tempNum) { Stack.push_front(tempNum); } for (deque<int>::iterator it = Stack.begin(); it != Stack.end(); it++) { deque<int>::iterator iMax = max_element(it, Stack.end()); if (iMax != it) { if (iMax != Stack.end() - 1) { reverse(iMax, Stack.end()); cout << distance(Stack.begin(), iMax) + 1 << ' '; } reverse(it, Stack.end()); cout << distance(Stack.begin(), it) + 1 << ' '; } } cout << '0' << endl; } /// return 0; }
相关文章推荐
- 煎饼(Stacks of Flapjacks,UVa 120)
- UVa 120 Stacks of Flapjacks 摞煎饼 - 插入排序
- Uva120 Stacks of Flapjacks 翻煎饼
- 例题8-1 煎饼 UVa120
- Uva120 Stacks of Flapjacks 翻煎饼
- 煎饼UVa120
- UVa Problem 120 Stacks of Flapjacks (煎饼堆)
- 煎饼排序 (Stacks of Flapjacks, Uva 120)
- UVa 120 煎饼堆
- UVA 120 煎饼
- Stacks of Flapjacks 翻煎饼-UVA120 白书第五章
- UVa 120 煎饼堆
- 例题8-1 煎饼 UVa 120
- UVa 120 煎饼
- UVA 120 Stacks of Flapjacks 煎饼
- △UVA120 - Stacks of Flapjacks
- uva120 stacks of flapjacks
- uva 120 - Stacks of Flapjacks
- UVA 120 Stacks of Flapjacks
- uva 120 Stacks of Flapjacks