Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register
欢迎参加IJCAI 2020麻将智能体竞赛,大奖等你拿!Welcome to IJCAI 2020 Mahjong AI competition with amazing prizes!

Re:递归,代码,此题坚决不用STL,那样太没意思

Posted by 50573750 at 2011-05-26 21:17:33 on Problem 1256
In Reply To:递归,代码,此题坚决不用STL,那样太没意思 Posted by:smilerxz at 2009-08-12 15:59:26
> #include <iostream>
> #include <algorithm>
> using namespace std;
> 
> #define MAXN 13
> 
> char a[MAXN + 1];
> int len;
> char flag[MAXN];
> char s[MAXN + 1];
> 
> bool cmp(char a, char b) {
>     return tolower(a) == tolower(b) ? a < b : tolower(a) < tolower(b);
> }
> 
> void solve(int n) {
>     if (n == len) {
>         puts(s);
>         return;
>     }
>     for (int i = 0; i < len; i++) {
>         if (! flag[i]) {
>             flag[i] = 1;
>             s[n] = a[i];
>             solve(n + 1);
>             flag[i] = 0;
>             while (i + 1 < len && a[i + 1] == a[i]) i++;
>         }
>     }
> }
> 
> int main() {
>     int CASE;
>     scanf("%d", &CASE);
>     while (CASE--) {
>         scanf("%s", a);
>         len = strlen(a);
>         sort(a, a + len, cmp);
>         memset(flag, 0, sizeof(flag));
>         s[len] = 0;
>         solve(0);
>     }
>     return 0;
> }

用stl不是超时就是超内存,过不去。。。反正就是最朴素的STL用法。。。

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator