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

329ms...这题输出要不少时间吧?dfs

Posted by KatrineYang at 2016-08-20 01:44:44 on Problem 1256
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;

int toNum(char c){
	if(c >= 'A' && c <= 'Z') return 2 * (c-'A');
	if(c >= 'a' && c <= 'z') return 2 * (c-'a') + 1;
	return -1;
}

char toChar(int q){
	if(q%2==0) return q/2 + 'A';
	return q/2 + 'a';
}

void dfs(int *gs, int *rec, int len, int rem){
	if(rem == 0){
		for(int i = 0; i < len; i++){
			printf("%c", toChar(rec[i]));
		}
		printf("\n");
		return;
	}
	for(int i = 0; i < 52; i++){
		if(gs[i] == 0) continue;
		gs[i]--;
		rec[len-rem] = i;
		dfs(gs, rec, len, rem-1);
		gs[i]++;
	}
}

int main() {
	int cases;
	scanf("%d", &cases);
	for(int ii = 0; ii < cases; ii++){
		char s[16];
		scanf("%s", s);
		int len = strlen(s);
		int gs[52] = {0};
		int rec[14];
		for(int i = 0; i < len; i++){
			gs[toNum(s[i])] ++;
		}
		dfs(gs, rec, len, len);
	}
	return 0;
}

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