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

Re:为啥会Memory Limit Exceeded啊

Posted by UESTCSYC at 2018-03-15 08:40:48 on Problem 1014
In Reply To:为啥会Memory Limit Exceeded啊 Posted by:acidsweet at 2012-12-19 16:57:12
> 看讨论大家都在讨论取模,有不少人都认为取模有问题,我是使用一般的BFS的,原本想最多也就TLE,没想到竟然MLE了,敢问我的代码的内存处理有问题吗?
> #include <iostream>
> #include <vector>
> #include <queue>
> using namespace std;
> class Node
> {
> public:
> 	int *array;
> 	int rest;
> 	Node(int *a,int b)
> 	{
> 		array=a;
> 		rest=b;
> 	}
> 	Node()
> 	{}
> };
> bool Judge(int array[],int sum)//BFS
> {
> 	queue<Node> mq;
> 	Node tmp;
> 	Node root=Node(array,sum);
> 	mq.push(root);//root
> 	int i;
> 	while(!mq.empty())
> 	{
> 		tmp=mq.front();
> 		if(tmp.rest==0) return true;
> 		if(tmp.rest<0)
> 		{
> 			mq.pop();continue;
> 		}
> 		for(i=5;i>=0;--i)
> 		{
> 			if(tmp.array[i]>0)
> 			{
> 				(tmp.array[i])--;
> 				tmp.rest-=(i+1);
> 				root=Node(tmp);
> 				mq.push(root);
> 				++(tmp.array[i]);
> 				tmp.rest+=(i+1);
> 			}
> 		}
> 		mq.pop();
> 	}
> 	return false;
> }
> int main()
> {
> 	int array[6];
> 	vector<bool> results;
> 	int sum,i;
> 	while(true)
> 	{
> 		sum=0;
> 		for(i=0;i<6;i++)
> 		{
> 			cin>>array[i];
> 			sum+=array[i];
> 		}
> 		if(sum==0)break;
> 		if((sum%2)!=0) 
> 		{
> 			results.push_back(false);//impossible to divide
> 			continue;
> 		}
> 		results.push_back(Judge(array,sum/2));//拼出一半
> 	}
> 	for(unsigned int i=0;i<results.size();i++)
> 	{
> 		cout<<"Collection #"<<(i+1)<<":"<<endl;
> 		if(results[i])
> 			cout<<"Can be divided."<<endl;
> 		else
> 			cout<<"Can't be divided."<<endl;
> 		}
> }

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