題目大意:給出2個水杯和目標的容量,輸出經過fill drop pour三種操作的最少步數。
這題思路還是比較清晰的,可是就是不知為什麼mle了,找不出來問題,先碼著放這裡,有空回來看。
mle:
#include#include#include#include#include#include#include#define inf 0x3f3f3f3f
using namespace std;
int a,b,c,cnt[105][105],faedge[105][105],mins,ans;
bool vis[105][105];
struct tie
tie(){}
};map> fanode;
void print(tie t)
while(!s.empty())
else
if(!vis[rra][rrb])}}
else if(i==5)
else
vis[rra][rrb]=true;
cnt[rra][rrb]=cnt[temp.ra][temp.rb]+1;
faedge[rra][rrb]=i;
fanode[rra][rrb].ra=temp.ra;
fanode[rra][rrb].rb=temp.rb;
q.push(tie(rra,rrb));}}
}}
return false;
}int main();
char map[maxn][maxn];
int a, b, k;
struct node
;bool bfs()
else
q.step++;
strcpy(q.str[q.step], "pour(1,2)");
if(!vis[q.vola][q.volb])}}
///把 b 倒滿
if(p.volb == 0)
}///把 b 中的水倒出來
else if(p.volb <= b)
if(p.vola < a)
else
q.step++;
strcpy(q.str[q.step], "pour(2,1)");
if(!vis[q.vola][q.volb])}}
}return false;
}int main()
return 0;
}
POJ 3414(BFS 輸出路徑 倒水問題)
題意 給你兩個容器,分別能裝下a公升水和b公升水,並且可以進行以下操作 fill i 將第i個容器從水龍頭裡裝滿 1 i 2 drop i 將第i個容器抽乾 pour i,j 將第i個容器裡的水倒入第j個容器 這次操作結束後產生兩種結果,一是第j個容器倒滿並且第i個容器依舊有剩餘,二是第i個容器裡的...
Poj 3414 Pots(BFS 列印路徑)
題意 給你兩個水杯的容積和乙個數m,讓你在任意乙個水杯中倒出乙個m,求最小步數,和輸出路徑。六種操作。題解 bfs六種操作。然後記錄路徑。用dfs反向查詢路徑。博主的方法比較笨,手寫了乙個佇列,然後記錄當前步是由佇列中那一步到達的。具體看 實現。include include includeusin...
POJ 3414 Pots(倒水問題 列印路徑)
分析這道題屬於倒水問題,思想不變,不過在此之上還需要列印路徑,需要在節點當中儲存操作o,還需要記錄每乙個節點的父親。include include include include includeusing namespace std const int n 100 10 int pot 2 c,vi...