• <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>

            The Fourth Dimension Space

            枯葉北風(fēng)寒,忽然年以殘,念往昔,語(yǔ)默心酸。二十光陰無(wú)一物,韶光賤,寐難安; 不畏形影單,道途阻且慢,哪曲折,如渡飛湍。斬浪劈波酬壯志,同把酒,共言歡! -如夢(mèng)令

            POJ 1606-Jugs

            本題的題意大致是:給你兩個(gè)容器,指定它們的容量Ca,Cb,還有一個(gè)目標(biāo)容量N;
            兩個(gè)容器初始含水量都是零,問(wèn)如何配制出容量為N的液體;

            我的做法很簡(jiǎn)單 BFS搜索,不過(guò)代碼實(shí)在太長(zhǎng)   在網(wǎng)上搜了一下 居然有一個(gè)500+B的代碼 看得不是很明白 希望有牛人能夠指點(diǎn)一下

            //This is the source code for Problem POJ 1606
            #include<iostream>
            #include
            <cmath>
            #include
            <cstring>
            #include
            <stack>
            using namespace std;



            struct node 
            {
                
                
            int ca;
                
            int cb;
                
            int pre;
            }
            line[100];
            int hash[10000];
            stack
            <node>mystack;





            int main()
            {
                
                
            int a,b,c;
                
            int front;
                
            int rear;
                
            while(scanf("%d%d%d",&a,&b,&c)!=EOF)
                
            {
                    memset(hash,
            0,sizeof(hash));
                    
            while(mystack.empty()!=true)
                        mystack.pop();

                    
                    node temp;
                    temp.ca
            =0;
                    temp.cb
            =0;
                    temp.pre
            =-1;
                    line[
            1]=temp;
                    front
            =1;
                    rear
            =1;
                    
            while(front<=rear)
                    
            {
                    
                        
            if(line[front].ca==c||line[front].cb==c)
                            
            break;
                        
            else if(line[front].ca!=a)
                        
            {
                            node temp;
                            temp.ca
            =a;
                            temp.cb
            =line[front].cb;
                            temp.pre
            =front;
                            
            //給出下一個(gè)狀態(tài)
                            int hashnum=temp.ca*10+temp.cb;
                            
            if(hash[hashnum]==0)
                            
            {
                                hash[hashnum]
            =1;
                                rear
            ++;
                                line[rear]
            =temp;
                            }
            //判重

                            
                            
                        }

                        
            if(line[front].cb!=b)
                        
            {
                            
                            node temp;
                            temp.cb
            =b;
                            temp.ca
            =line[front].ca;
                            temp.pre
            =front;
                            
            //給出下一個(gè)狀態(tài)
                            int hashnum=temp.ca*10+temp.cb;
                            
            if(hash[hashnum]==0)
                            
            {
                                hash[hashnum]
            =1;
                                rear
            ++;
                                line[rear]
            =temp;
                            }
            //判重
                        
                        }

                        
            if(line[front].ca!=0)
                        
            {
                            
                            node temp;
                            temp.ca
            =0;
                            temp.cb
            =line[front].cb;
                            temp.pre
            =front;
                            
            //給出下一個(gè)狀態(tài)
                        

                            
            int hashnum=temp.ca*10+temp.cb;
                            
            if(hash[hashnum]==0)
                            
            {
                                hash[hashnum]
            =1;
                                rear
            ++;
                                line[rear]
            =temp;
                            }
            //判重
                            
                        }

                        
            if(line[front].cb!=0)
                        
            {
                            
                            node temp;
                            temp.cb
            =0;
                            temp.ca
            =line[front].ca;
                            temp.pre
            =front;
                            
            //給出下一個(gè)狀態(tài)


                            
            int hashnum=temp.ca*10+temp.cb;
                            
            if(hash[hashnum]==0)
                            
            {
                                hash[hashnum]
            =1;
                                rear
            ++;
                                line[rear]
            =temp;
                            }
            //判重
                        
                        }




                        
            if(line[front].ca!=0&&line[front].cb!=b)
                        
            {
                            
                            node temp;
                
                            
            if(b-line[front].cb>=line[front].ca)
                            
            {
                                temp.ca
            =0;
                                temp.cb
            =line[front].cb+line[front].ca;
                                temp.pre
            =front;
                            }

                            
            else
                            
            {
                                temp.ca
            =line[front].ca-(b-line[front].cb);
                                temp.cb
            =b;
                                temp.pre
            =front;
                            }


                            
            //給出下一個(gè)狀態(tài)
                            
                            
                            
            int hashnum=temp.ca*10+temp.cb;
                            
            if(hash[hashnum]==0)
                            
            {
                                hash[hashnum]
            =1;
                                rear
            ++;
                                line[rear]
            =temp;
                            }
            //判重
                            
                        }




                        
            if(line[front].ca!=a&&line[front].cb!=0)
                        
            {
                            
                            node temp;
                            
                            
            if(a-line[front].ca>=line[front].cb)
                            
            {
                                temp.cb
            =0;
                                temp.ca
            =line[front].ca+line[front].cb;
                                temp.pre
            =front;
                            }

                            
            else
                            
            {
                                temp.cb
            =line[front].cb-(a-line[front].ca);
                                temp.ca
            =a;
                                temp.pre
            =front;
                            }

                            
                            
            //給出下一個(gè)狀態(tài)
                            
                            
                            
            int hashnum=temp.ca*10+temp.cb;
                            
            if(hash[hashnum]==0)
                            
            {
                                hash[hashnum]
            =1;
                                rear
            ++;
                                line[rear]
            =temp;
                            }
            //判重
                            
                        }

                        front
            ++;
                    }


                    
            int tempnum=front;
                    
            while(line[tempnum].pre!=-1)
                    
            {

                        mystack.push(line[tempnum]);
                        tempnum
            =line[tempnum].pre;
                    }

                    node tempnode1;
                    tempnode1.ca
            =0;
                    tempnode1.cb
            =0;
                    tempnode1.pre
            =-1;

                    node tempnode2;

                    
            while(mystack.empty()!=true)
                    
            {
                        tempnode2
            =mystack.top();
                        mystack.pop();
                        
            if(tempnode1.ca!=0&&tempnode2.ca==0&&(tempnode1.cb==tempnode2.cb))
                            printf(
            "empty A\n");
                        
            else if(tempnode1.cb!=0&&tempnode2.cb==0&&(tempnode1.ca==tempnode2.ca))
                            printf(
            "empty B\n");
                        
            else if(tempnode1.ca!=a&&tempnode2.ca==a&&(tempnode1.cb==tempnode2.cb))
                            printf(
            "fill A\n");
                        
            else if(tempnode1.cb!=b&&tempnode2.cb==b&&(tempnode1.ca==tempnode2.ca))
                            printf(
            "fill B\n");
                        
            else if(tempnode2.ca>tempnode1.ca)
                            printf(
            "pour B A\n");
                        
            else 
                            printf(
            "pour A B\n");
                        tempnode1
            =tempnode2;
                    }

                    printf(
            "success\n");
                }

                
            return 0;
            }




            500B的代碼如下:
            #include<iostream>
            using namespace std;
            int main()
            {
            int ca,cb,n;
            int a,b;
            while(cin>>ca>>cb>>n)
            {
                a
            =0;b=0;
            while(1)
            {
                
            if(b==cb) {cout<<"empty B"<<endl;b=0;if(b==n) {cout<<"success"<<endl;break;}}
                
            else if(a==0{cout<<"fill A"<<endl;a=ca;if(b==n) {cout<<"success"<<endl;break;}}
                
            else if(b+a<cb) {cout<<"pour A B"<<endl;b=b+a;a=0;if(b==n) {cout<<"success"<<endl;break;}}
                
            else if(b+a>=cb) {cout<<"pour A B"<<endl;a=a+b-cb;b=cb;if(b==n) {cout<<"success"<<endl;break;}}
            }

            }

            system(
            "pause");
            return 0;
            }

            希望大家能給我解釋一下 多謝^_^

            posted on 2009-07-06 16:38 abilitytao 閱讀(601) 評(píng)論(1)  編輯 收藏 引用

            評(píng)論

            # re: POJ 1606-Jugs 2010-11-20 16:33 天青色~~

            學(xué)長(zhǎng)還有1天告別acm,這個(gè)東東還需要人來(lái)解釋嗎?呵呵^_^
            因?yàn)檫@題是special judge,有多解,所以直接模擬……  回復(fù)  更多評(píng)論   


            只有注冊(cè)用戶(hù)登錄后才能發(fā)表評(píng)論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問(wèn)   Chat2DB   管理


            2020国产成人久久精品| 国产精品无码久久久久久| 久久国产乱子伦精品免费午夜| 一本久久a久久精品综合夜夜| 久久嫩草影院免费看夜色| 久久这里都是精品| 蜜桃麻豆www久久| 久久伊人五月丁香狠狠色| 99久久免费国产特黄| 一本一道久久a久久精品综合 | 久久久久久久人妻无码中文字幕爆 | 国产精品久久久久久福利漫画 | 无码久久精品国产亚洲Av影片| 99精品久久久久中文字幕| 色综合久久久久综合99| 精品久久久久久久久中文字幕| 亚洲伊人久久成综合人影院 | 色妞色综合久久夜夜| 欧美午夜精品久久久久久浪潮| 久久精品无码午夜福利理论片| 亚洲国产高清精品线久久| 久久99精品国产麻豆宅宅| 亚洲精品无码久久久久sm| 中文成人久久久久影院免费观看| 99精品伊人久久久大香线蕉| 精品久久久久中文字幕日本| 亚洲中文字幕无码久久精品1| 亚洲一本综合久久| 久久99精品久久只有精品| 色婷婷久久综合中文久久一本| 国产L精品国产亚洲区久久| 久久久久亚洲AV无码网站| 欧美精品一区二区精品久久| 精品永久久福利一区二区| 久久国内免费视频| 亚洲一区精品伊人久久伊人| 国产国产成人久久精品| 色噜噜狠狠先锋影音久久| 久久综合九色综合精品| 国产午夜精品理论片久久| 久久精品国产99国产精品澳门 |