| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
????为什么是输入格式的问题?? 求解释》》》》 (附代码)> main函数中改为:
> while (cin>>ca>>cb>>N)
> bfs(N);
> 即可AC.
用while(scanf("%d%d%d",&X,&Y,&N)!=EOF) —————— WA
用while(scanf("%d%d%d",&X,&Y,&N)==3) —————— WA
用while(cin>>X>>Y>>N) —————————— AC
求解释》》》》??
// 1606 Jugs
#include<iostream>
using namespace std;
#define MAX 101010100
struct Node
{
int a,b;
int from,oper;
}p[MAX];
int X,Y,N,top,tail;
char ans[10][100]={"fill A","empty A","fill B","empty B","pour A B","pour B A"};
bool v[1010][1010];
void dfs(int t)
{
if(p[t].from<0) return ;
dfs(p[t].from);
printf("%s\n",ans[p[t].oper-1]);
}
int main()
{
int i,j,va,vb;
while(cin>>X>>Y>>N) //---->这里的输入格式;
{
memset(v,0,sizeof(v));
v[0][0]=1;
top=tail=0;
p[0].a=p[0].b=0;p[0].from=-1;
while(top<=tail)
{
va=p[top].a;vb=p[top].b;
if(!v[X][vb])
{
v[X][vb]=1;
p[++tail].a=X;
p[tail].b=vb;
p[tail].from=top;
p[tail].oper=1;
}
if(!v[0][vb])
{
v[0][vb]=1;
p[++tail].a=0;
p[tail].b=vb;
p[tail].from=top;
p[tail].oper=2;
}
if(!v[va][Y])
{
v[va][Y]=1;
p[++tail].a=va;
p[tail].b=Y;
p[tail].from=top;
p[tail].oper=3;
if(Y==N) break;
}
if(!v[va][0])
{
v[va][0]=1;
p[++tail].a=va;
p[tail].b=0;
p[tail].from=top;
p[tail].oper=4;
}
if(va+vb<=Y)
{
if(!v[0][va+vb])
{
v[0][va+vb]=1;
p[++tail].a=0;
p[tail].b=va+vb;
p[tail].from=top;
p[tail].oper=5;
if(va+vb==N) break;
}
}
else
{
if(!v[va+vb-Y][Y])
{
v[va+vb-Y][Y]=1;
p[++tail].a=va+va-Y;
p[tail].b=Y;
p[tail].from=top;
p[tail].oper=5;
if(Y==N) break;
}
}
if(vb+va<=X)
{
if(!v[vb+va][0])
{
v[va+vb][0]=1;
p[++tail].a=va+vb;
p[tail].b=0;
p[tail].from=top;
p[tail].oper=6;
}
}
else
{
if(!v[X][vb+va-X])
{
v[X][vb+va-X]=1;
p[++tail].a=X;
p[tail].b=va+vb-X;
p[tail].from=top;
p[tail].oper=6;
if(va+vb-X==N) break;
}
}
top++;
}
dfs(tail);
puts("success");
}
system("pause");
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator