日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

题目1457:非常可乐(广度优先遍历BFS)

發布時間:2023/12/1 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 题目1457:非常可乐(广度优先遍历BFS) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題目鏈接:http://ac.jobdu.com/problem.php?pid=1457

詳解鏈接:https://github.com/zpfbuaa/JobduInCPlusPlus

參考代碼:

// // 1457 非常可樂.cpp // Jobdu // // Created by PengFei_Zheng on 22/04/2017. // Copyright ? 2017 PengFei_Zheng. All rights reserved. // #include <stdio.h> #include <iostream> #include <algorithm> #include <string.h> #include <cmath> #include <queue> #define MAX_SIZE 101 using namespace std;int s, n, m;struct N{int a;int b;int c;int t; };queue<N> myQueue; bool visit[MAX_SIZE][MAX_SIZE][MAX_SIZE];void x2y(int &x,int size_x, int &y,int size_y){if(size_y - y >= x){y+=x;x = 0;}else{x -=(size_y-y);y = size_y;} }int BFS(int s, int n, int m){while(!myQueue.empty()){N nowP = myQueue.front();myQueue.pop();int a, b, c;a = nowP.a;b = nowP.b;c = nowP.c;x2y(a,s,b,n);// a--->bif(visit[a][b][c]==false){visit[a][b][c]=true;N tmp;tmp.a = a;tmp.b = b;tmp.c = c;tmp.t = nowP.t+1;if((a==s/2 && b==s/2) || (a==s/2 &&c==s/2) || (b==s/2 && c==s/2) ) return tmp.t;myQueue.push(tmp);}a = nowP.a;b = nowP.b;c = nowP.c;x2y(a,s,c,m);// a--->cif(visit[a][b][c]==false){visit[a][b][c]=true;N tmp;tmp.a = a;tmp.b = b;tmp.c = c;tmp.t = nowP.t+1;if((a==s/2 && b==s/2) || (a==s/2 &&c==s/2) || (b==s/2 && c==s/2) ) return tmp.t;myQueue.push(tmp);}a = nowP.a;b = nowP.b;c = nowP.c;x2y(b,n,a,s);// b--->aif(visit[a][b][c]==false){visit[a][b][c]=true;N tmp;tmp.a = a;tmp.b = b;tmp.c = c;tmp.t = nowP.t+1;if((a==s/2 && b==s/2) || (a==s/2 &&c==s/2) || (b==s/2 && c==s/2) ) return tmp.t;myQueue.push(tmp);}a = nowP.a;b = nowP.b;c = nowP.c;x2y(b,n,c,m);// b--->cif(visit[a][b][c]==false){visit[a][b][c]=true;N tmp;tmp.a = a;tmp.b = b;tmp.c = c;tmp.t = nowP.t+1;if((a==s/2 && b==s/2) || (a==s/2 &&c==s/2) || (b==s/2 && c==s/2) ) return tmp.t;myQueue.push(tmp);}a = nowP.a;b = nowP.b;c = nowP.c;x2y(c,m,a,s);// c--->aif(visit[a][b][c]==false){visit[a][b][c]=true;N tmp;tmp.a = a;tmp.b = b;tmp.c = c;tmp.t = nowP.t+1;if((a==s/2 && b==s/2) || (a==s/2 &&c==s/2) || (b==s/2 && c==s/2) ) return tmp.t;myQueue.push(tmp);}a = nowP.a;b = nowP.b;c = nowP.c;x2y(c,m,b,n);// c--->bif(visit[a][b][c]==false){visit[a][b][c]=true;N tmp;tmp.a = a;tmp.b = b;tmp.c = c;tmp.t = nowP.t+1;if((a==s/2 && b==s/2) || (a==s/2 &&c==s/2) || (b==s/2 && c==s/2) ) return tmp.t;myQueue.push(tmp);}}return -1; }int main(){while(scanf("%d%d%d",&s,&n,&m)!=EOF){if(s==0) break;if(s%2==1){printf("NO\n");continue;}for(int i = 0 ; i <= s ; i++){for(int j = 0 ; j <= n ; j++){for(int k = 0 ; k <= m ; k++){visit[i][j][k]=false;}}}while(!myQueue.empty()) myQueue.pop();N tmp;tmp.a = s;tmp.b = tmp.c = tmp.t = 0;myQueue.push(tmp);visit[s][0][0]=true;int ans = BFS(s,n,m);ans == -1 ? printf("NO\n") : printf("%d\n",ans);} } /**************************************************************Problem: 1457User: zpfbuaaLanguage: C++Result: AcceptedTime:10 msMemory:2528 kb ****************************************************************/

?

轉載于:https://www.cnblogs.com/zpfbuaa/p/6750319.html

總結

以上是生活随笔為你收集整理的题目1457:非常可乐(广度优先遍历BFS)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。