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啊

Posted by zhanglongpan at 2009-07-30 21:02:19 on Problem 3414
#pragma warning (disable: 4786)
#include <iostream>
#include <stack>
#include <string>
#include <memory>

using namespace std;
struct jh
{
	int a1,a2;
};
int main()
{
	int a1=0,a2=0,m=0,n=0,ans=0;      //A1,A2表示单前桶中水的数量 ,m,n分别为童的容量
//	int used[100][100]={0};				//如果某个组合已经被使用,则不进入队列。
	cin>>m>>n>>ans;
	             
	jh BFS[80536];					//存储解空间的队列
	//下面开始搜索
	int i=1;
	memset(BFS,0,sizeof(BFS));
	while(true)
	{
		
		/*if(used[100][100])
		{
			i++;
			continue;
		}*/
		switch(i%6)
		{
		case 1: { BFS[i].a1=m;BFS[i].a2=BFS[(i-1)/6].a2;
				if(BFS[i].a1==ans || BFS[i].a2==ans)  
									goto end;}break;
		case 2:  {BFS[i].a1=0;BFS[i].a2=BFS[(i-1)/6].a2;}break;
			case 3:  {
				
								BFS[i].a2=BFS[(i-1)/6].a1+BFS[(i-1)/6].a2; 
								BFS[i].a1=0;
								if(BFS[i].a2>n) 
								{
									BFS[i].a1=BFS[i].a2-n;
									BFS[i].a2=n;
								}
								if(BFS[i].a1==ans || BFS[i].a2==ans)  
									goto end;
					 }  break;
			case 4:  {BFS[i].a2=n;
				BFS[i].a1=BFS[(i-1)/6].a1;
				if(BFS[i].a1==ans || BFS[i].a2==ans)  
									goto end;}break;
			case 5:  {BFS[i].a2=0;
					BFS[i].a1=BFS[(i-1)/6].a1;
					 }break;
			case 0:  {
						BFS[i].a1=BFS[(i-1)/6].a1+BFS[(i-1)/6].a2;  
						BFS[i].a2=0;
						
						if(BFS[i].a1>m) {
							BFS[i].a2=BFS[i].a1-m;
									BFS[i].a1=m;
						}
					
						if(BFS[i].a1==ans || BFS[i].a2==ans)  
									goto end;
					

					 }  break;
		}		
		i++;

	}	
if(i>70000) cout<<"impossible\n";
end:
		stack<string> str;
	while(i!=0)
	{
		
	
		switch(i%6)
		{
		case 1:  str.push("FILL(1)\n"); break;
		case 2:  str.push("DROP(1)\n");break;
		case 3:	 str.push("POUR(1,2)\n");break;
		case 4:  str.push("FILL(2)\n");break;
		case 5:  str.push("DROP(2)\n");break;
		case 0:	 str.push("POUR(2,1)\n");break;
		}
		i=(i-1)/6;
	}
	cout<<str.size()<<endl;
	while(!str.empty())
	{
		cout<<str.top();
		str.pop();
	}                



	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