UVa-10098-Generating Fast
来源:互联网 发布:淘宝卖的猛犸象牙猫腻 编辑:程序博客网 时间:2024/06/10 02:24
AOAPC I: Beginning Algorithm Contests (Rujia Liu) :: Volume 3. Brute Force :: Elementary Skills
// 10098 - Generating Fast#include <iostream>#include <algorithm>#include <cstring>using namespace std;int main(void){int i, n, len;char s[11];while(cin >> n)while(n--){cin >> s;len = strlen(s);sort(s, s+len);do{for(i=0; i<len; i++)cout << s[i];cout << endl;}while(next_permutation(s, s+len));cout << endl;}return 0;}
Time limit exceeded:
// 10098 - Generating Fast#include <iostream>#include <algorithm>#include <cstring>using namespace std;void print_permutation(int cur, int n, char* s, char p, char q){int i, j;char ch;if(cur == n){for(i=0; i<n; i++)cout << s[i];cout << endl;}else{for(ch=p; ch<=q; ch++){int ok = 1;for(j=0; j<cur; j++)if(s[j] == ch)ok = 0;if(ok){s[cur] = ch;print_permutation(cur+1, n, s, p, q);}}}}int main(void){int n, len;char s[11];while(cin >> n)while(n--){cin >> s;len = strlen(s);sort(s, s+len);print_permutation(0, len, s, s[0], s[len-1]);cout << endl;}return 0;}
0 0
- UVa 10098 Generating Fast
- uva 10098 - Generating Fast
- UVa 10098 Generating Fast
- uva 10098 - Generating Fast
- UVa 10098 - Generating Fast
- UVa 10098 Generating Fast
- Uva 10098 - Generating Fast
- UVA 10098 - Generating Fast
- UVa 10098 - Generating Fast
- uva 10098 - Generating Fast
- UVa 10098: Generating Fast
- uva 10098 Generating Fast
- uva - 10098 - Generating Fast
- UVa 10098 - Generating Fast
- uva 10098 - Generating Fast
- UVa 10098 - Generating Fast
- uva 10098 - Generating Fast
- UVa 10098 - Generating Fast
- Simplify Path
- 《老罗的Android之旅》导读PPT
- 家训
- 2014年8月4日 金砖银行来了
- Excel公式与函数案例速查手册/电脑技巧从入门到精通丛书
- UVa-10098-Generating Fast
- 【ZOJ】2770 Burn the Linked Camp 差分约束
- LeetCode 3 Max Points on a Line
- CHROME中好用的插件
- CNZZ网站流量统计原理简析
- 脑动力:C语言函数速查效率手册(附DVD光盘1张) [平
- 前端不为人知的一面--前端冷知识集锦
- cocos2d-x 之 XML
- 线段树模版