日韩性视频-久久久蜜桃-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【广搜】的全部內容,希望文章能夠幫你解決所遇到的問題。

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

    主站蜘蛛池模板: 经典三级视频 | 久久久久一区二区三区四区 | 777理伦三级做爰 | 日韩成人高清在线 | 在线免费h | 人妻精品久久久久中文字幕 | 97成人精品视频在线观看 | 人人妻人人澡人人爽精品欧美一区 | 黄片毛片 | 亚洲精品久久久中文字幕痴女 | 国产精品三区在线观看 | 日日操夜夜操天天操 | 精品久久一区 | 中文在线最新版天堂 | 欧美 亚洲 一区 | 色婷婷av久久久久久久 | 黄色一级大片免费看 | 天天精品 | 欧美三级一区二区 | 都市激情第一页 | 久久国产精品国产精品 | 古装做爰无遮挡三级 | 日韩中文字 | 狠狠干女人| 国产1区2区3区中文字幕 | www.欧美| 国产吧在线 | 国产精品一级片在线观看 | 亚洲精品国产精品乱码不卡√香蕉 | 成人网在线视频 | 秋霞一级全黄大片 | 超碰123 | 风间由美一区 | av青青| 色呦呦视频在线观看 | 激情文学亚洲 | 亚洲一区二区91 | 新版天堂资源中文8在线 | 日韩成人精品视频 | 欧美一区二区三区免费在线观看 | 久久91亚洲人成电影网站 | 国产成人啪免费观看软件 | 欧美大屁股熟妇bbbbbb | 色戒av| 国产精品天堂 | 99ri视频| www.五月天婷婷 | 99精品99| 色综合久久久久 | 天天干天天摸 | 91精品人妻一区二区三区四区 | 欧美人妻少妇一区二区三区 | 日日夜夜欧美 | 晨勃顶到尿h1v1 | 99999av | 国外成人性视频免费 | 国产中文一区二区三区 | 东北熟女一区二区三区 | 中文字幕avav| 在线免费看黄 | 嫩草社区 | 在线免费观看福利 | 色哟哟视频网站 | 亚洲伦理在线视频 | 日韩在线资源 | 亚洲欧美日韩电影 | 99热在线只有精品 | 久久久久成人精品无码 | 国产精品激情 | 欧美亚洲一区二区三区 | 国产精品98 | 偷操| 在线免费看mv的网站入口 | 日韩中文字幕2019 | 午夜在线精品偷拍 | 国产精品白虎 | 丝袜国产一区 | 日韩精品在线看 | 国产69精品麻豆 | av中文字幕一区 | 久久国产小视频 | 国产一区二区电影 | 完美搭档在线观看 | 99热精品国产 | 久久bb| 桃色在线视频 | 偷自拍 | 色呦呦在线 | 中文字幕亚洲国产 | 毛片无遮挡高清免费观看 | 性高跟鞋xxxxhd国产电影 | 一级黄色短片 | 欧美极品在线播放 | 99精品视频一区二区三区 | 影音av资源 | 欧美精品久久久久久 | 五月激情五月婷婷 | 国产91沙发系列 | 黄色中文视频 |