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

郁闷!!用个STL竟然遇到了罕见的Memory Limit Exceeded ,这是什么状况?

Posted by a798253982 at 2013-07-28 20:53:34 on Problem 1426
#include <iostream> 
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;

typedef struct
{
	int num[101];
	int n;
}Point;
 
Point ans;
int n;

void bfs(int x)
{
	queue<Point> q;
	Point p0,p1,p2;
	
	p0.num[0]=1;p0.n=1;
	q.push(p0);
	
	while(!q.empty())
	{
		p1=q.front();q.pop();
		int temp=0;
		for(int i=0;i<p1.n;i++)
			temp = (temp*10+p1.num[i])%n;
		for(int i=0;i<2;i++)
		{
			p2=p1;p2.num[p2.n]=i;p2.n+=1;
			int temp1=(temp*10+i)%n;
			if(temp1==0){
				ans=p2;
				while(!q.empty()) q.pop();
				return;
			}
			q.push(p2);
		}	
	}
}

int main(){
	while(~scanf("%d",&n))
	{	
		if(n==0)
		    break;
		bfs(n);
		for(int i=0;i<ans.n;i++)
			printf("%d",ans.num[i]);
		printf("\n");	
	}
	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