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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

Pots POJ - 3414

發布時間:2025/4/16 编程问答 18 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Pots POJ - 3414 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

You are given two pots, having the volume of?A?and?B?liters respectively. The following operations can be performed:

  • FILL(i)??????? fill the pot?i?(1 ≤?i?≤ 2) from the tap;
  • DROP(i)????? empty the pot?i?to the drain;
  • POUR(i,j)??? pour from pot?i?to pot?j; after this operation either the pot?jis full (and there may be some water left in the pot?i), or the pot?i?is empty (and all its contents have been moved to the pot?j).
  • Write a program to find the shortest possible sequence of these operations that will yield exactly?C?liters of water in one of the pots.

    Input

    On the first and only line are the numbers?A,?B, and?C. These are all integers in the range from 1 to 100 and?C≤max(A,B).

    Output

    The first line of the output must contain the length of the sequence of operations?K. The following?K?lines must each describe one operation. If there are several sequences of minimal length, output any one of them. If the desired result can’t be achieved, the first and only line of the file must contain the word ‘impossible’.

    Sample Input

    3 5 4

    Sample Output

    6 FILL(2) POUR(2,1) DROP(1) POUR(2,1) FILL(2) POUR(2,1) #include<iostream> #include<algorithm> #include<cstring> #include<queue> #include<stack> using namespace std; struct cup{int x,y;int step;int flag;//標記操作cup*pre; //標記路徑 }; queue<cup> q; stack<int> r; int a,b,e; int vis[117][117]={0};//標記當前狀態是否到達過 int ans; void print(){while(!r.empty()){int i=r.top();r.pop();switch(i){case 1:cout<<"FILL(1)"<<endl;break;case 2:cout<<"FILL(2)"<<endl;break;case 3:cout<<"DROP(1)"<<endl;break;case 4:cout<<"DROP(2)"<<endl;break;case 5:cout<<"POUR(1,2)"<<endl;break;case 6:cout<<"POUR(2,1)"<<endl;break;}} } void bfs(int x,int y){cup c;cup t[317];///目前瓶子里剩余的水量c.x=0,c.y=0;c.flag=0;c.pre=NULL;c.step=0;q.push(c);vis[x][y]=1;int count =-1;while(!q.empty()){count++;t[count]=q.front();q.pop();for(int i=1;i<=6;i++){switch(i){case 1:{c.x=a;c.y=t[count].y;c.flag=1;break;}case 2:{c.x=t[count].x;c.y=b;c.flag=2;break;}case 3:{c.x=0;c.y=t[count].y;c.flag=3;break;}case 4:{c.x=t[count].x;c.y=0;c.flag=4;break;}case 5:{if(t[count].x>b-t[count].y){c.x=t[count].x-(b-t[count].y);c.y=b;}else{c.x=0;c.y=t[count].y+t[count].x;}c.flag=5;break;}case 6:{if(t[count].y>a-t[count].x){c.y=t[count].y-(a-t[count].x);c.x=a;}else{c.y=0;c.x=t[count].x+t[count].y;}c.flag=6;break;} } if(vis[c.x][c.y])continue;vis[c.x][c.y]=1;c.step=t[count].step+1;c.pre=&t[count];if(c.x==e||c.y==e){ans=c.step;while(c.pre){r.push(c.flag);c = *c.pre;}return;}q.push(c);}} } int main(){cin>>a>>b>>e;bfs(0,0);if(ans==0)cout<<"impossible"<<endl;else{cout<<ans<<endl;print();}return 0; }

    ?

    轉載于:https://www.cnblogs.com/CuteAbacus/p/9492151.html

    總結

    以上是生活随笔為你收集整理的Pots POJ - 3414的全部內容,希望文章能夠幫你解決所遇到的問題。

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

    主站蜘蛛池模板: 免费毛片播放 | 一道本av | 亚洲乱码国产乱码精品精98午夜 | 成人区人妻精品一区二区网站 | 少妇性l交大片 | 亚洲精品成 | 亚洲欧美经典 | av55 | 免费高清av在线看 | 丰满少妇中文字幕 | 白浆网站 | 亚洲人妻一区二区 | 精品网站999| 欧美日韩乱| 特级毛片在线播放 | 黄色一级片欧美 | 中文在线一区二区三区 | 成年人久久 | 人人艹人人 | 国产精选一区二区三区 | 日韩毛片一级 | 人妻少妇一区二区 | 日本欧美国产 | 久久久久久久亚洲av无码 | 麻豆啪啪| 日本乱偷中文字幕 | 无码日韩精品视频 | 中国黄色小视频 | 性感美女福利视频 | 免费日本特黄 | 18岁免费观看电视连续剧 | 中文在线а√天堂官网 | 97色伦影院| 香蕉大久久 | 午夜在线观看影院 | 亚洲私人影院 | 蜜臂av| 激情视频网址 | 欧美男人亚洲天堂 | 黄色精品在线观看 | 中国一级片黄色一级片黄 | 欧美一线高本道 | 无码精品国产一区二区三区 | 男人天堂2014 | 九九色九九 | 国产精品123区 | 91在现看 | 波多野结衣高清视频 | 亚洲图片中文字幕 | 国产高清不卡视频 | 性欧美18一19性猛交 | 日韩中文久久 | www.国产.com| aaa色| 麻豆一区二区三区在线观看 | 国产精品久久久久一区二区 | 欧美深夜在线 | 亚洲激情在线观看 | 欧美成人三级 | 91九色蝌蚪91por成人 | 一区二区三区日本视频 | 久久精品美女 | 免费h漫禁漫天天堂 | 日批视频免费在线观看 | 亚洲夜夜操 | 伊人久久久久久久久久 | 亚洲性图av | av在线免费播放 | 久久成人毛片 | 日日夜夜精品视频 | 浮妇高潮喷白浆视频 | 欧美熟妇精品久久久久久 | 琪琪av在线 | 日本三级免费网站 | 国产精品无码av在线播放 | 日本久久久久 | 狼人狠狠干 | 日日夜夜综合 | 天天久久| 成人在线视频网站 | 温柔少妇的高潮呻吟 | 天天影视亚洲 | 国产福利网 | 粉嫩aⅴ一区二区三区 | 久久久精品区 | 日本男女啪啪 | 久久精品国产网红主播 | 自拍视频国产 | 猎艳山村丰满少妇 | 伊人春色在线视频 | 香蕉视频911| 哺乳期给上司喂奶hd | 91啦丨九色丨刺激 | 欧美tickle狂笑裸体vk | 国语播放老妇呻吟对白 | 国产精品色综合 | 视频精品一区 | 欧美第一页在线观看 | 欧美日韩一区二区三区在线 | 黑人高潮一区二区三区在线看 |