| ||||||||||
| 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 | |||||||||
C++ac,G++wa是什么原因导致的??呜呜呜呜#include<iostream>
#include<queue>
using namespace std;
const int N=105;
int x[N][N],y[500000][5];
int a,b,c;
struct node {
int x,y;
};
node Start,Cur,Next;
int bfs() {
queue<node> q;
q.push(Start);
while(q.size()) {
Cur=q.front();
q.pop();
Next.x=a;
Next.y=Cur.y;
if(x[Next.x][Next.y]==0) {
x[Next.x][Next.y]=x[Cur.x][Cur.y]+1;
if(Next.x==c||Next.y==c)
return x[Next.x][Next.y];
q.push(Next);
}
Next.x=Cur.x;
Next.y=b;
if(x[Next.x][Next.y]==0) {
x[Next.x][Next.y]=x[Cur.x][Cur.y]+1;
if(Next.x==c||Next.y==c)
return x[Next.x][Next.y];
q.push(Next);
}
Next.x=min(a,Cur.x+Cur.y);
Next.y=max(0,Cur.x+Cur.y-a);
if(x[Next.x][Next.y]==0) {
x[Next.x][Next.y]=x[Cur.x][Cur.y]+1;
if(Next.x==c||Next.y==c)
return x[Next.x][Next.y];
q.push(Next);
}
Next.y=min(b,Cur.x+Cur.y);
Next.x=max(0,Cur.x+Cur.y-b);
if(x[Next.x][Next.y]==0) {
x[Next.x][Next.y]=x[Cur.x][Cur.y]+1;
if(Next.x==c||Next.y==c)
return x[Next.x][Next.y];
q.push(Next);
}
Next.x=0;
Next.y=Cur.y;
if(x[Next.x][Next.y]==0) {
x[Next.x][Next.y]=x[Cur.x][Cur.y]+1;
if(Next.x==c||Next.y==c)
return x[Next.x][Next.y];
q.push(Next);
}
Next.x=Cur.x;
Next.y=0;
if(x[Next.x][Next.y]==0) {
x[Next.x][Next.y]=x[Cur.x][Cur.y]+1;
if(Next.x==c||Next.y==c)
return x[Next.x][Next.y];
q.push(Next);
}
}
return -1;
}
int main() {
int p,ansx=-1,ansy=-1,o=0,ans,flag;
cin>>a>>b>>c;
Start.x=Start.y=0;
p=bfs();
if(p==-1)
cout<<"impossible";
else {
if(ansx==-1&&ansy==-1) {
for(int i=0; i<=a; i++) {
if(x[i][c]==p) {
ansx=i;
ansy=c;
break;
}
}
}
if(ansx==-1&&ansy==-1) {
for(int i=0; i<=b; i++) {
if(x[c][i]==p) {
ansx=c;
ansy=i;
break;
}
}
}
while(ans!=0) {
ans=x[ansx][ansy];
if(ansx==a) {
flag=0;
for(int i=0; i<a; i++) {
if(x[i][ansy]==ans-1) {
ansx=i;
y[o][0]=1;
y[o++][1]=1;
flag=1;
break;
}
}
if(flag)
continue;
}
if(ansy==b) {
flag=0;
for(int i=0; i<b; i++) {
if(x[ansx][i]==ans-1) {
ansy=i;
y[o][0]=1;
y[o++][1]=2;
flag=1;
break;
}
}
if(flag)
continue;
}
if(ansx==0) {
flag=0;
for(int i=1; i<=a; i++) {
if(x[i][ansy]==ans-1) {
ansx=i;
y[o][0]=2;
y[o++][1]=1;
flag=1;
break;
}
}
if(flag)
continue;
}
if(ansy==0) {
flag=0;
for(int i=1; i<=b; i++) {
if(x[ansx][i]==ans-1) {
ansy=i;
y[o][0]=2;
y[o++][1]=2;
flag=1;
break;
}
}
if(flag)
continue;
}
flag=0;
for(int i=1; i<=min(a-ansx,ansy); i++) {
if(x[ansx+i][ansy-i]==ans-1) {
ansx+=i;
ansy-=i;
y[o][0]=3;
y[o][1]=1;
y[o++][2]=2;
flag=1;
break;
}
}
if(flag)
continue;
flag=0;
for(int i=1; i<=min(ansx,b-ansy); i++) {
if(x[ansx-i][ansy+i]==ans-1) {
ansx-=i;
ansy+=i;
y[o][0]=3;
y[o][1]=2;
y[o++][2]=1;
flag=1;
break;
}
}
if(flag)
continue;
}
cout<<p<<endl;
for(int i=o-1; i>=0; i--) {
if(y[i][0]==1)
cout<<"FILL("<<y[i][1]<<")\n";
else if(y[i][0]==2)
cout<<"DROP("<<y[i][1]<<")\n";
else
cout<<"POUR("<<y[i][1]<<","<<y[i][2]<<")\n";
}
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator