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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

POJ 3414 Pots【广搜】

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

Description

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 ito the drain;
  • POUR(i,j)??? pour from pot i to pot j; after this operation either the pot j is 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) code: View Code #include<stdio.h>
    #include<string.h>
    #define clr(x)memset(x,0,sizeof(x))
    int v[1001][1001];
    int va;
    int vb;
    struct node
    {
    int x,y,xu,step;
    }q[100000];
    int pre[100000];
    //1 full 1 2 full 2 3 drop 1 4 drop 2 5 from a to b 6 from b to a
    void print(int x)
    {
    if(pre[x]!=0)
    print(pre[x]);
    //printf("%d\n",q[x].xu);
    if(q[x].xu==1)
    printf("FILL(1)\n");
    else if(q[x].xu==2)
    printf("FILL(2)\n");
    else if(q[x].xu==3)
    printf("DROP(1)\n");
    else if(q[x].xu==4)
    printf("DROP(2)\n");
    else if(q[x].xu==5)
    printf("POUR(1,2)\n");
    else printf("POUR(2,1)\n");
    }
    int main()
    {
    int a,b,c,i,j,front,rear,tmp,v1,v2,res,ans;
    while(scanf("%d%d%d",&a,&b,&c)!=EOF)
    {
    va=vb=0;
    front=rear=0;
    q[rear].xu=0; q[rear].step=0; q[rear].x=0; q[rear++].y=0;
    res=-1;
    v[0][0]=1;

    memset(pre,0,sizeof(pre));
    while(front<=rear)
    {
    va=q[front].x; vb=q[front].y;
    //printf("%d %d\n",va,vb);
    if(va==c||vb==c) { res=q[front].step;ans=front; break;}
    if(!v[a][vb]) { v[a][vb]=1; q[rear].x=a; q[rear].y=vb; q[rear].xu=1; pre[rear]=front; q[rear++].step=q[front].step+1; }
    if(!v[va][b]) { v[va][b]=1; q[rear].x=va; q[rear].y=b; q[rear].xu=2; pre[rear]=front; q[rear++].step=q[front].step+1; }
    if(!v[0][vb]) { v[0][vb]=1; q[rear].x=0; q[rear].y=vb; q[rear].xu=3; pre[rear]=front; q[rear++].step=q[front].step+1; }
    if(!v[va][0]) { v[va][0]=1; q[rear].x=va; q[rear].y=0; q[rear].xu=4; pre[rear]=front; q[rear++].step=q[front].step+1; }
    if((va+vb)/b<1){
    if(!v[0][va+vb]){ v[0][va+vb]=1; q[rear].x=0; q[rear].y=va+vb; q[rear].xu=5; pre[rear]=front; q[rear++].step=q[front].step+1; }
    }
    else if(!v[va-(b-vb)][b]) { v[va-(b-vb)][b]=1; q[rear].x=va-(b-vb); q[rear].y=b; q[rear].xu=5; pre[rear]=front; q[rear++].step=q[front].step+1; }
    if((va+vb)/a<1){
    if(!v[va+vb][0]){ v[va+vb][0]=1; q[rear].x=va+vb; q[rear].y=0; q[rear].xu= 6; pre[rear]=front; q[rear++].step=q[front].step+1; }
    }
    else if(!v[a][vb-(a-va)]) { v[a][vb-(a-va)]=1; q[rear].x=a; q[rear].y=vb-(a-va); q[rear].xu=6; pre[rear]=front; q[rear++].step=q[front].step+1; }
    front++;
    }
    if(res==-1)printf("impossible\n");
    else {
    printf("%d\n",res);
    print(ans);
    }
    }
    return 0;
    }

    轉載于:https://www.cnblogs.com/dream-wind/archive/2012/03/22/2412181.html

    總結

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

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

    主站蜘蛛池模板: 西欧毛片 | 在线观看视频一区 | 国产美女精品久久 | 91成人看| 中文字幕第八页 | 国产成人在线精品 | 中文字幕一区二区免费 | 国产免费一区二区三区在线观看 | 久操网站 | 亚洲一区中文字幕在线 | 伦理亚洲| 青青偷拍视频 | 天天操天天透 | 顶级嫩模啪啪呻吟不断好爽 | 怡春院欧美 | 色婷婷av一区二区三区gif | 国产亚洲色婷婷久久99精品 | 国产精品国产一区二区三区四区 | av片在线观看免费 | 91av爱爱 | 波多野结衣亚洲一区 | www.久久色 | 国产黄色激情视频 | 草草影院ccyycom | 狠狠操夜夜 | 国产极品一区二区 | 韩国电影一区 | 俺也来俺也去俺也射 | 少妇在线观看 | 成年人网站在线观看视频 | 国产日韩欧美精品一区 | 最近日韩中文字幕 | wwwwww在线观看 | 色乱码一区二区三区熟女 | 色狠av | 亚洲 小说区 图片区 | 情侣作爱视频网站 | 最新黄色av网站 | 一本色道综合久久欧美日韩精品 | 天堂av8| 中文字幕第35页 | 成人中文字幕在线 | 亚洲一区二区三区四区在线观看 | 久久精品男人的天堂 | 亚洲精品影视 | 久久久久久久福利 | 91看片就是不一样 | 久久久女人 | 97超级碰碰人妻中文字幕 | 免费一级suv好看的国产网站 | 午夜va | 一本到在线视频 | 在线免费观看网站入口在哪 | 欧美视频xxxx | 女生喷水视频 | 伊人精品在线观看 | 伊人www| 国产无遮挡a片又黄又爽 | 国模私拍在线观看 | 国产精品999久久久 在线青草 | 成人动漫一区二区 | 黄色免费视屏 | 中文字幕1区2区 | 黄色一毛片 | 亚洲av无码久久精品色欲 | 久99精品| 国产伦精品一区二区三区视频孕妇 | 国产粉嫩在线 | 91刺激视频| 精品无码久久久久久久久果冻 | 国产在线最新 | 午夜福利毛片 | 激情午夜天 | 亚洲黄网av | 欧美日韩伊人 | 欧美老肥婆性猛交视频 | 色宗合 | 久久99国产精品久久99 | 性开放淫合集 | 黄色片中文字幕 | 在线观看网页视频 | 亚洲av毛片一区二二区三三区 | 玉足脚交榨精h文 | 久久精品99北条麻妃 | 精品少妇久久久久久888优播 | 玩偶游戏在线观看免费 | 99免费精品 | 超碰日日干 | 国产精品国产三级国产专播品爱网 | 97超碰总站| 亚洲福利国产 | 亚洲成a人v欧美综合天堂麻豆 | 美女视频黄色在线观看 | 国产91在线免费观看 | 17草在线| 日韩av中文字幕在线 | 永久久久久久久 | 少妇太爽了太深了太硬了 | 九九爱精品 |