青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

poj3414

Pots

Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 6116 Accepted: 2582 Special Judge

Description

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

  1. FILL(i)        fill the pot i (1 ≤ i ≤ 2) from the tap;
  2. DROP(i)      empty the pot i to the drain;
  3. 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)
挺簡單的題目
沒看完題目,不知道還有impossible的情況,wa了一次,然后第二遍忘了輸出impossible之后要return,re一次
呃,蛋疼
  1#include<stdio.h>
  2#include<string.h>
  3#include<math.h>
  4int a,b,c;
  5struct node
  6{
  7    int a,b,d,d1;
  8}
;
  9struct node q[100050];
 10int wh[10005];
 11int num0[10005],num;
 12short flag[105][105];
 13int head,tail,k;
 14int bfs()
 15{
 16    int nowa,nowb,aa,bb;
 17    head=0;
 18    tail=1;
 19    q[tail].a=0;
 20    q[tail].b=0;
 21    flag[0][0]=1;
 22    wh[tail]=0;
 23    while (head<tail)
 24    {
 25        head++;
 26        nowa=q[head].a;
 27        nowb=q[head].b;
 28        if ((q[head].a==c)||(q[head].b==c))
 29        {
 30            return head;
 31        }

 32        if (nowa!=a)
 33        {
 34            if (!flag[a][nowb])
 35            {
 36                tail++;
 37                q[tail].a=a;
 38                q[tail].b=nowb;
 39                q[tail].d=1;
 40                q[tail].d1=1;
 41                wh[tail]=head;
 42                flag[a][nowb]=1;
 43            }

 44        }

 45        if (nowb!=b)
 46        {
 47            if (!flag[nowa][b])
 48            {
 49                tail++;
 50                q[tail].a=nowa;
 51                q[tail].b=b;
 52                q[tail].d=1;
 53                q[tail].d1=2;
 54                wh[tail]=head;
 55                flag[nowa][b]=1;
 56            }

 57        }

 58        if (nowa!=0)
 59        {
 60            if (!flag[0][nowb])
 61            {
 62                tail++;
 63                q[tail].a=0;
 64                q[tail].b=nowb;
 65                q[tail].d=2;
 66                q[tail].d1=1;
 67                wh[tail]=head;
 68                flag[0][nowb]=1;
 69            }

 70        }

 71        if (nowb!=0)
 72        {
 73            if (!flag[nowa][0])
 74            {
 75                tail++;
 76                q[tail].a=nowa;
 77                q[tail].b=0;
 78                q[tail].d=2;
 79                q[tail].d1=2;
 80                wh[tail]=head;
 81                flag[nowa][0]=1;
 82            }

 83        }

 84        if (nowa!=0)
 85        {
 86            if (nowa>=b-nowb)
 87            {
 88                aa=nowa+nowb-b;
 89                //printf("aa=%d\n",aa);
 90                bb=b;
 91                if (!flag[aa][bb])
 92                {
 93                    tail++;
 94                    q[tail].a=aa;
 95                    q[tail].b=bb;
 96                    q[tail].d=3;
 97                    q[tail].d1=1;
 98                    wh[tail]=head;
 99                    flag[aa][bb]=1;
100                }

101            }

102            else if(nowa<b-nowb)
103            {
104                aa=0;
105                bb=nowb+nowa;
106                if (!flag[aa][bb])
107                {
108                    tail++;
109                    q[tail].a=aa;
110                    q[tail].b=bb;
111                    q[tail].d=3;
112                    q[tail].d1=1;
113                    wh[tail]=head;
114                    flag[aa][bb]=1;
115                }

116            }

117        }

118        if (nowb!=0)
119        {
120            if (nowb>=a-nowa)
121            {
122                aa=a;
123                bb=nowb+nowa-a;
124                if (!flag[aa][bb])
125                {
126                    tail++;
127                    q[tail].a=aa;
128                    q[tail].b=bb;
129                    q[tail].d=3;
130                    q[tail].d1=2;
131                    wh[tail]=head;
132                    flag[aa][bb]=1;
133                }

134            }

135            else if (nowb<a-nowa)
136            {
137                bb=0;
138                aa=nowa+nowb;
139                if (!flag[aa][bb])
140                {
141                    tail++;
142                    q[tail].a=aa;
143                    q[tail].b=bb;
144                    q[tail].d=3;
145                    q[tail].d1=2;
146                    wh[tail]=head;
147                    flag[aa][bb]=1;
148                }

149            }

150        }

151    }

152    return -1;
153}

154void print(int k1)
155{
156    int i;
157    i=k1;
158    if (k1==-1)
159    {
160        printf("impossible\n");
161        return;
162    }

163    num=0;
164    while(i!=1)
165    {
166        num++;
167        num0[num]=i;
168        i=wh[i];
169    }

170    printf("%d\n",num);
171    for(i=num; i>=1; i--)
172        if (q[num0[i]].d==1)
173        {
174            printf("FILL(%d)\n",q[num0[i]].d1);
175        }

176        else if(q[num0[i]].d==2)
177        {
178            printf("DROP(%d)\n",q[num0[i]].d1);
179        }

180        else if(q[num0[i]].d==3)
181        {
182            if (q[num0[i]].d1==1)
183            {
184                printf("POUR(1,2)\n");
185            }

186            else if(q[num0[i]].d1==2)
187            {
188                printf("POUR(2,1)\n");
189            }

190        }

191}

192int main()
193{
194    scanf("%d%d%d",&a,&b,&c);
195    memset(flag,0,sizeof(flag));
196    if ((c>a)&&(c>b))
197    {
198        k=-1;
199        print(k);
200    }

201    else
202    {
203        k=bfs();
204        print(k);
205    }

206    return 0;
207}

208

posted on 2012-03-20 19:47 jh818012 閱讀(1183) 評論(2)  編輯 收藏 引用

評論

# re: poj3414 2012-04-02 17:48 王私江

200+行,跑了多少ms呢?我的130+行哦,你菜啦,哈哈。  回復  更多評論   

# re: poj3414[未登錄] 2012-04-02 19:59 jh818012

@王私江
0ms  回復  更多評論   


只有注冊用戶登錄后才能發表評論。
網站導航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


<2025年11月>
2627282930311
2345678
9101112131415
16171819202122
23242526272829
30123456

導航

統計

常用鏈接

留言簿

文章檔案(85)

搜索

最新評論

  • 1.?re: poj1426
  • 我嚓,,輝哥,,居然搜到你的題解了
  • --season
  • 2.?re: poj3083
  • @王私江
    (8+i)&3 相當于是 取余3的意思 因為 3 的 二進制是 000011 和(8+i)
  • --游客
  • 3.?re: poj3414[未登錄]
  • @王私江
    0ms
  • --jh818012
  • 4.?re: poj3414
  • 200+行,跑了多少ms呢?我的130+行哦,你菜啦,哈哈。
  • --王私江
  • 5.?re: poj1426
  • 評論內容較長,點擊標題查看
  • --王私江
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            一区二区三区欧美亚洲| 国产欧美69| 久久中文字幕一区| 亚洲电影av在线| 欧美国产第一页| 亚洲视频日本| 免费欧美日韩国产三级电影| 一本色道久久综合狠狠躁的推荐| 国产精品国产三级国产专播精品人 | 尤物九九久久国产精品的特点| 麻豆精品国产91久久久久久| 日韩视频三区| 久久婷婷综合激情| 亚洲天堂男人| 在线播放豆国产99亚洲| 国产精品xxxxx| 久久综合九色99| 亚洲一区二区高清视频| 亚洲电影在线观看| 一区二区三区不卡视频在线观看 | 久久久久久久波多野高潮日日| 在线免费观看视频一区| 欧美日韩一二三区| 久久综合狠狠综合久久综合88| 中日韩美女免费视频网站在线观看| 蜜桃久久av一区| 欧美一区观看| 一本大道久久a久久精品综合| 黄色精品一二区| 国产精品成人播放| 免费一区视频| 久久久久久夜| 亚洲一区三区在线观看| 亚洲国产一区二区精品专区| 久久精品青青大伊人av| 在线视频精品一区| 亚洲日本中文字幕| 在线欧美日韩| 国产一区二区三区黄视频| 欧美午夜精品伦理| 欧美精品国产| 欧美成人精品在线播放| 久久琪琪电影院| 久久xxxx| 亚洲字幕在线观看| 亚洲人成亚洲人成在线观看图片| 欧美成人一区二区| 蜜臀99久久精品久久久久久软件 | 欧美激情一区二区| 久久婷婷亚洲| 久久精品日产第一区二区| 午夜在线电影亚洲一区| 亚洲免费伊人电影在线观看av| 日韩午夜电影在线观看| 最近中文字幕日韩精品| 亚洲激情欧美| 亚洲国产综合91精品麻豆| 黑人巨大精品欧美黑白配亚洲| 国产深夜精品| 国产欧美一区二区三区久久| 国产农村妇女精品一二区| 国产精品女主播在线观看| 国产精品青草久久久久福利99| 国产精品都在这里| 国产精品久久一卡二卡| 国产精品一区二区在线观看| 欧美亚洲成人精品| 国产精品高清免费在线观看| 欧美日韩专区在线| 国产精品久久久久久久久久免费| 国产精品麻豆成人av电影艾秋| 国产精品嫩草影院一区二区| 国产日韩欧美在线一区| 激情亚洲网站| 亚洲高清一二三区| 亚洲精品字幕| 亚洲香蕉成视频在线观看| 亚洲字幕在线观看| 欧美一区二区三区精品| 久久午夜羞羞影院免费观看| 欧美黄色日本| 一个色综合导航| 先锋影音久久| 麻豆av一区二区三区久久| 欧美剧在线观看| 欧美日韩视频在线第一区| 国产精品久久久久久久久婷婷| 国产精品私人影院| 国产最新精品精品你懂的| 国产亚洲欧美一级| 亚洲福利在线看| 在线亚洲欧美视频| 亚洲综合色丁香婷婷六月图片| 欧美专区亚洲专区| 欧美成人午夜激情在线| 亚洲精品中文在线| 亚洲欧美在线磁力| 美女91精品| 国产精品久久久久aaaa| 国内精品久久久久影院优| 亚洲电影免费在线| 亚洲永久网站| 乱中年女人伦av一区二区| 亚洲三级免费观看| 性色一区二区| 久久精品麻豆| 欧美α欧美αv大片| 香蕉久久一区二区不卡无毒影院| 久久久久国产一区二区三区四区| 美国成人毛片| 亚洲九九爱视频| 午夜精品一区二区三区在线播放| 蜜桃av综合| 国产精品青草综合久久久久99| 亚洲福利一区| 久久成人一区| 亚洲另类一区二区| 久久久国产91| 国产精品久久久久久一区二区三区| 在线观看日韩av| 欧美亚洲系列| 亚洲国产精品成人综合| 香蕉国产精品偷在线观看不卡 | 欧美一区二区三区四区夜夜大片| 欧美福利小视频| 国产一区香蕉久久| 亚洲一区二区三区四区五区午夜| 欧美大片网址| 久久精品91久久久久久再现| 欧美日韩国产专区| 精品动漫av| 欧美夜福利tv在线| 一区二区免费看| 欧美成黄导航| 黄色影院成人| 亚洲综合欧美日韩| 亚洲精品色婷婷福利天堂| 另类人畜视频在线| 激情综合久久| 久久久欧美精品sm网站| 亚洲一二三区精品| 狂野欧美一区| 好看的av在线不卡观看| 欧美一区二区大片| 日韩系列欧美系列| 久久久久久午夜| 黄色亚洲精品| 久久精品人人做人人爽电影蜜月| 亚洲午夜电影网| 欧美色欧美亚洲高清在线视频| 亚洲欧洲一区二区三区在线观看| 久久精品亚洲精品| 一区二区三区日韩精品| 欧美国产日韩一区二区在线观看| 狠狠爱成人网| 久久在线播放| 久久精品国产免费看久久精品| 国产精品午夜电影| 亚洲天堂av综合网| 99视频有精品| 欧美三级乱码| 亚洲在线观看| 亚洲午夜精品久久| 国产精品视频久久一区| 亚洲精品欧美日韩| 亚洲国产成人高清精品| 欧美成人黑人xx视频免费观看| 在线日韩视频| 欧美激情一区二区三区蜜桃视频| 农夫在线精品视频免费观看| 一区二区亚洲精品国产| 久久精品亚洲一区二区三区浴池| 欧美一区二区三区另类 | 欧美日韩精品免费观看视频| 99re在线精品| 99re在线精品| 国产精品美女999| 欧美一级夜夜爽| 久久激情五月丁香伊人| 亚洲国产小视频| 亚洲美女精品久久| 国产精品国产三级国产aⅴ9色| 国产精品99久久不卡二区| 一级日韩一区在线观看| 国产日韩一区二区三区在线播放| 久久手机免费观看| 美国三级日本三级久久99| 日韩午夜激情电影| 亚洲一区二区三区免费在线观看| 国产精品综合色区在线观看| 久久视频在线看| 美女成人午夜| 亚洲视频在线观看免费| 亚洲一区在线播放| 激情校园亚洲| 亚洲日韩欧美一区二区在线| 国产精品一区二区黑丝| 美女精品国产| 欧美a级片一区| 亚洲一区二区三区三|