<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    emu in blogjava

      BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
      171 隨筆 :: 103 文章 :: 1052 評論 :: 2 Trackbacks

    Problem Statement

    ???? There are three stacks of crates - two of them outside of the warehouse, and one inside the warehouse. We have a crane that can move one crate at a time, and we would like to move all of the crates to the stack inside the warehouse. A heavier crate can never be stacked on top of a lighter crate, and all three initial stacks obey that rule.

    Create a class CraneWork that contains a method moves that is given int[]s stack1, stack2, and warehouse containing the initial three stacks, and returns the minimum number of moves required to move all the crates into the warehouse stack. The elements of stack1, stack2, and warehouse represent the weights of the crates and are given from top to bottom (and thus in non-decreasing order of weight).

    Definition

    ????
    Class: CraneWork
    Method: moves
    Parameters: int[], int[], int[]
    Returns: int
    Method signature: int moves(int[] stack1, int[] stack2, int[] warehouse)
    (be sure your method is public)
    ????

    Constraints

    - stack1, stack2, and warehouse will each contain between 0 and 20 elements, inclusive.
    - The total number of elements in the three stacks will be between 1 and 20, inclusive.
    - Each element in the three stacks will be between 1 and 200, inclusive.
    - stack1, stack2, and warehouse will each be in non-decreasing order.

    Examples

    0)
    ????
    {3,50}
    {}
    {1,2,50,50,50}
    Returns: 12
    Move 3 to stack2, 1 to stack1, 2 to stack2, 1 to stack2, 50 to warehouse, 1 to warehouse, 2 to stack1, 1 to stack1, 3 to warehouse, 1 to stack2, 2 to warehouse, 1 to warehouse.
    1)
    ????
    {50}
    {50}
    {10,20,30}
    Returns: 17
    Start by moving 50 from stack2 to stack1. It then takes 7 moves to transfer the 10,20,30 to stack 2, 2 moves to transfer the 2 50's to the warehouse, and 7 more to transfer the 10,20,30 to the warehouse.
    2)
    ????
    {}
    {}
    {2,5,6,7}
    Returns: 0
    All the crates are already in the warehouse.
    3)
    ????
    {1,2,3}
    {}
    {}
    Returns: 7
    Move 1 from stack1 to warehouse, 2 from stack1 to stack2, 1 from warehouse to stack2, 3 from stack1 to warehouse, 1 from stack2 to stack1, 2 from stack2 to warehouse, 1 from stack1 to warehouse.

    This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.

    posted on 2006-09-05 10:21 emu 閱讀(6623) 評論(7)  編輯  收藏 所屬分類: google編程大賽模擬題及入圍賽真題

    評論

    # re: 1000分模擬題CraneWork 2007-06-09 11:02 匿名
    #include <iostream>
    using namespace std;


    class CStack{
    public:
    CStack(){
    memset(data,0,100*sizeof(int));
    index=0;
    }
    virtual~CStack(){}
    int Pop() { sum++; return data[index--];}
    void Push(int D) { data[++index]=D; }
    int Find(int D,int I)
    {
    for(int i=I;i<=index;i++)
    if(data[i]<D)
    return i;
    return index+1;
    }
    int Show(int I)
    {
    if(index==0) return 0;
    if(I>index||I<1)
    return 0;
    return data[I];
    }
    bool Istop(int T)
    {
    if(T==index) return true;
    else return false;
    }
    void Show()
    {
    if(index==0)
    {
    cout<<"空"<<endl;
    return;
    }

    for(int i=index;i>0;i--)
    cout<<data[i]<<" ";
    cout<<endl;
    }
    public:
    static int sum;
    private:
    int data[100];
    int index;
    };
    int CStack::sum=0;

    CStack stack[3];


    void show()
    {
    cout<<"////////////////"<<endl;
    for(int i=0;i<3;i++)
    stack[i].Show();
    cout<<"////////////////"<<endl;
    }
    void CraneWork(int a,int k1,int b,int k2,int c,int k3)
    {
    int x=stack[a].Show(k1);
    int y=stack[b].Show(k2);
    int z=stack[c].Show(k3);
    if(x==0&&y==0) return;

    if(z>=x&&z>=y)
    {
    if(x>=y)
    {
    int k=stack[c].Find(x,k3);
    CraneWork(a,k1+1,c,k,b,k2);
    stack[c].Push(stack[a].Pop());
    show();
    CraneWork(b,k2,a,k1,c,k+1);
    }
    else
    {
    int k=stack[c].Find(y,k3);
    CraneWork(b,k2+1,c,k,a,k1);
    stack[c].Push(stack[b].Pop());
    CraneWork(a,k1,b,k2,c,k+1);
    }
    }
    if(x>z&&x>=y)
    {
    if(x==y)
    {
    if(stack[a].Istop(k1)&&stack[b].Istop(k2))
    {
    stack[a].Push(stack[b].Pop());
    CraneWork(a,k1+2,c,k3,b,k2);
    stack[c].Push(stack[a].Pop());
    stack[c].Push(stack[a].Pop());
    CraneWork(a,k1,b,k2,c,k3+2);
    return;
    }
    }
    CraneWork(a,k1+1,c,k3,b,k2);
    stack[c].Push(stack[a].Pop());
    show();
    CraneWork(a,k1,b,k2,c,k3+1);

    }
    if(y>z&&y>x)
    {
    CraneWork(b,k2+1,c,k3,a,k1);
    stack[c].Push(stack[b].Pop());
    show();
    CraneWork(a,k1,b,k2,c,k3+1);
    }
    }



    int _tmain(int argc, _TCHAR* argv[])
    {
    /*stack[0].Push(50);
    stack[0].Push(3);
    stack[2].Push(50);
    stack[2].Push(50);
    stack[2].Push(50);
    stack[2].Push(2);
    stack[2].Push(1);*/
    /*stack[0].Push(3);
    stack[0].Push(2);
    stack[0].Push(1);*/
    stack[0].Push(50);
    stack[1].Push(50);
    stack[2].Push(30);
    stack[2].Push(20);
    stack[2].Push(10);


    show();
    CraneWork(0,1,1,1,2,1);
    show();
    cout<<"次數為:"<<CStack::sum<<endl;
    return 0;
    }
      回復  更多評論
      

    # re: 1000分模擬題CraneWork [未登錄] 2007-08-06 18:52 zero
    very easy!  回復  更多評論
      

    # re: 1000分模擬題CraneWork [未登錄] 2007-11-11 22:23 y
    g sdfg  回復  更多評論
      

    # re: 1000分模擬題CraneWork 2008-09-19 09:26
    比賽題目都是英文么  回復  更多評論
      

    # re: 1000分模擬題CraneWork 2008-09-22 11:21 hejian
    這是一道漢諾塔的變種題,不知使用進位迭代的方式還有沒有效,有時間可以試一下。  回復  更多評論
      

    # re: 1000分模擬題CraneWork 2008-11-27 17:59 誠人
    一直對google技術佩服!我也要研究一番。  回復  更多評論
      

    # re: 1000分模擬題CraneWork [未登錄] 2010-10-03 23:54 無名
    鑒定完畢,此程序有問題。  回復  更多評論
      

    主站蜘蛛池模板: 国产成人免费高清激情视频| 精品国产麻豆免费人成网站| 在线观看免费人成视频色| 亚洲AV无码精品色午夜在线观看| 亚欧国产一级在线免费| 亚洲日韩在线观看| 亚洲免费一区二区| 亚洲色欲一区二区三区在线观看| 国产免费牲交视频免费播放 | 又大又黄又粗又爽的免费视频| 一本色道久久88—综合亚洲精品| 久久天天躁狠狠躁夜夜免费观看| 亚洲永久在线观看| 白白国产永久免费视频| 特黄aa级毛片免费视频播放| 亚洲婷婷国产精品电影人久久| 特级aaaaaaaaa毛片免费视频| 中文字幕亚洲一区二区三区| 成人黄网站片免费视频| 亚洲黄色网址在线观看| 日韩吃奶摸下AA片免费观看| 日韩国产精品亚洲а∨天堂免| 亚洲国产精品尤物YW在线观看| 国产亚洲免费的视频看| 亚洲国产综合第一精品小说| 日韩免费视频在线观看| 人妻免费久久久久久久了| 亚洲国产精品无码AAA片| 2022久久国产精品免费热麻豆| 中文无码亚洲精品字幕| 久久精品国产精品亚洲| 色猫咪免费人成网站在线观看| 亚洲av无码不卡久久| 免费少妇a级毛片| 成在人线av无码免费高潮喷水| 亚洲春色另类小说| 免费不卡中文字幕在线| 免费无码又爽又刺激高潮视频| 亚洲综合激情五月色一区| 亚洲愉拍99热成人精品热久久| 午夜免费1000部|