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

why RE ????!!!!

Posted by houyu111 at 2010-12-22 22:58:49 on Problem 1465
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAX_N 10000 
#define MAX_M 100 
short int n, m;
short int fount, rear;
short int mod_flag[MAX_N];
char digits[12];
typedef struct 
{
	short int mod;
	short int count;
	char ans[MAX_M];
}Out_Q;
Out_Q q[MAX_N];

insert_sort()
{
	char tmp;
	int i, j, k;
	for(i=2;i<=m;++i){
		tmp = digits[i];
		for(j=1;j<i;++j){
			if(digits[j] > tmp)
				break;
		}
		for(k=i;k>j;--k) digits[k] = digits[k-1];
		digits[j] = tmp;
	}
}

void work();
void BFS();

int main()
{
	freopen("1136-input", "r", stdin);
	while(scanf("%d", &n) == 1){
		int i;
		scanf("%d", &m);
		for(i=1;i<=m;++i){
			getchar();
			digits[i] = getchar();
		}
		if(n){
			work();
		}
		else  printf("0\n");
	}
	return 0;
}

void work()
{
	memset(mod_flag, 0, sizeof(mod_flag));
	insert_sort();
	fount = rear = 0;
	BFS();
}

void BFS()
{
	int i;
	for(i=1;i<=m;++i){
		if(digits[i] == '0') continue;
		short int mod = (digits[i] - '0') % n;
		mod_flag[mod] = 1;
		q[(++rear) % MAX_N].mod = mod;
		short int k = q[rear % MAX_N].count = 1;
		q[rear % MAX_N].ans[k] = digits[i];
	}
	while((++fount) % MAX_N <= rear){
		if(q[fount].mod == 0){
			puts(q[fount].ans+1);
			return;
		}
		for(i=1;i<=m;++i){
			Out_Q tmp = q[fount];
			tmp.mod = (q[fount].mod * 10 + digits[i] - '0') % n;
			if(mod_flag[tmp.mod]) continue;
			mod_flag[tmp.mod] = 1;
			tmp.ans[++tmp.count] = digits[i];
			q[(++rear) % MAX_N] = tmp;
		}
	}
	printf("0\n");
}

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