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

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

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

    emu in blogjava

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

    Problem Statement
    ????
    A group of vertical blocks are placed densely one after another on the ground. The blocks each have a width of 1, but their heights may vary. For example, if the heights of the vertical blocks are given as {1,5,5,1,6,1}, the configuration would look like the following picture:


        ×
     ×× ×
     ×× ×
     ×× ×
     ×× ×
    ××××××
     
    Your task is to reproduce the exact shape of this structure using some number of non-intersecting rectangles. You will be given a int[] heights representing the heights of the vertical blocks from left to right. Return the minimal number of rectangles necessary to perform this task with the given configuration of blocks.
    Definition
    ????
    Class:
    BlockStructure
    Method:
    cover
    Parameters:
    int[]
    Returns:
    int
    Method signature:
    int cover(int[] heights)
    (be sure your method is public)
    ????

    Constraints
    -
    heights will have between 1 and 50 elements, inclusive.
    -
    Each element of heights will be between 1 and 1000, inclusive.
    Examples
    0)

    ????
    {1,5,5,1,6,1}
    Returns: 3
     
    We can use rectangles with sizes 6x1, 2x4 and 1x5.

        ×
     ×× ×
     ×× ×
     ×× ×
     ×× ×
    ××××××

    1)

    ????
    {2,2,2,4,4}
    Returns: 2
     
    We can use a 3x2 rectangle and a 2x4 rectangle.


       ××
       ××
    ×××××
    ×××××


    2)

    ????
    {6,6,6,6,6,6}
    Returns: 1
    The structure is a rectangle.
    3)

    ××××××
    ××××××
    ××××××
    ××××××
    ××××××
    ××××××


    ????
    {71,44,95,16,10,80,12,17,98,61}
    Returns: 10
    It's impossible to use less than 10 rectangles.
    4)

    ????
    {100,100,97,100,100,100,97,98,99,99}
    Returns: 5

    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 2005-12-20 10:28 emu 閱讀(1986) 評論(3)  編輯  收藏 所屬分類: google編程大賽模擬題及入圍賽真題

    評論

    # re: google中國編程挑戰(zhàn)賽入圍賽真題 -- BlockStructure(500分) 2005-12-21 14:06 emu
    我覺得這組解是干擾數(shù)據(jù):

    {2,2,2,4,4}
    Returns: 2

    We can use a 3x2 rectangle and a 2x4 rectangle.



       ××
       ××
    ×××××
    ×××××


    如果題目提供的解是這樣:



       ××
       ××
    ×××××
    ×××××


    答案就容易找的多了。  回復(fù)  更多評論
      

    # re: google中國編程挑戰(zhàn)賽入圍賽真題 -- BlockStructure(500分) 2006-06-28 15:43 深藍(lán)色心情
    public static int count(int[] vs){
    Arrays.sort(vs) ;
    int min = vs[0] ;

    //把最低下一行刪掉。
    List list = new LinkedList() ;
    for(int i = 0 ; i < vs.length ; i++){
    if(min != vs[i]){
    int leftValue = vs[i] - min ;
    if(leftValue > 0 ){
    list.add(new Integer(leftValue)) ;
    }
    }
    }

    int maxBox = 1 ;

    //分組
    int step = 0 ;
    int maxSize = list.size() ;
    for(int i = 0 ; i < maxSize ; i++){
    step = ((Integer)list.get(i)).intValue() ;
    do{
    if(i < maxSize){
    int nextValue = -1000 ;
    if(i + 1 < maxSize){
    nextValue = ((Integer)list.get(i + 1)).intValue() ;
    }
    if(step == nextValue){
    i++ ;
    }else{
    maxBox++ ;
    break ;
    }
    }
    }while(i < maxSize) ;
    }

    return maxBox ;
    }


    public static void main(String[] args) {

    int[] vs = {1,5,5,1,6,1} ;

    System.out.println(TestPlay.count(vs)) ;

    System.out.println(TestPlay.count(new int[]{6,6,6,6,6,6})) ;

    System.out.println(TestPlay.count(new int[]{2,2,2,4,4})) ;

    System.out.println(TestPlay.count(new int[]{71,44,95,16,10,80,12,17,98,61})) ;
    }

    花了20分鐘才寫出來.......,幸虧沒去比賽。
    不能輸入<0的數(shù),大家看看這樣子寫是對的嗎?
      回復(fù)  更多評論
      

    # re: google中國編程挑戰(zhàn)賽入圍賽真題 -- BlockStructure(500分) 2008-06-20 21:31 j
    看看我的是否更簡單些:
    #include"stdio.h"
    int make(int *T,int p,int dem,int *n,int *min)
    {
    *min=10000;
    *n=0;
    for(int i=p;i<dem;i++)
    if(T[i]>0)
    {
    int s=i;
    while(T[s]>0&&s<dem)
    {
    if(T[s]<*min)
    *min=T[s];
    (*n)++;
    s++;
    }
    return i;
    }
    return dem;
    }
    void Sub(int *T,int s,int n,int min)
    {
    for(int i=0;i<n;i++)
    T[s+i]-=min;
    }
    int main(int argc, char* argv[])
    { int p=0,n,m;
    int col[5]={3,3,6,6,6};
    while(true)
    {
    p=make(col,p,5,&n,&m);
    if(p==5)
    break;
    printf("width:%d,height:%d\n",n,m);
    Sub(col,p,n,m);
    }
    return 0;
    }
      回復(fù)  更多評論
      

    主站蜘蛛池模板: 99久久人妻精品免费二区| 免费激情网站国产高清第一页| 国产日韩一区二区三免费高清 | 久久亚洲国产成人精品无码区| 久久人午夜亚洲精品无码区| 日韩免费视频播放| 亚洲伊人久久大香线蕉综合图片| 一级毛片aa高清免费观看| 中文字幕亚洲免费无线观看日本 | 91精品免费在线观看| 亚洲成av人片不卡无码| 9久9久女女免费精品视频在线观看| 亚洲永久在线观看| 日韩免费视频播播| 黄床大片免费30分钟国产精品| 亚洲爆乳精品无码一区二区三区| 国产精品白浆在线观看免费| 亚洲激情视频网站| 女人18毛片水真多免费播放| 色视频在线观看免费| 国产亚洲精品美女久久久| 最近2019免费中文字幕6| 日韩亚洲不卡在线视频中文字幕在线观看| 成人毛片18女人毛片免费视频未 | 大地资源在线资源免费观看| 日本久久久久亚洲中字幕| 久久精品免费一区二区喷潮| 日韩在线观看视频免费| 亚洲午夜未满十八勿入| 成人午夜性A级毛片免费| 一级做a爰片久久毛片免费陪| 亚洲av无码成h人动漫无遮挡| 91香蕉视频免费| 精品国产福利尤物免费| va天堂va亚洲va影视中文字幕 | 中文字幕无线码中文字幕免费 | 亚洲线精品一区二区三区影音先锋| 免费精品无码AV片在线观看| 亚洲国产AV无码一区二区三区| 国产亚洲一区二区在线观看| 嫩草视频在线免费观看|