<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

         You are given a black and white image in a String[], image. Character j of element i (both 0-based indices) of image represents the pixel in row i, column j. 'X' characters represent black pixels and '.' characters represent white pixels. You are given a String[], crops, which contains a series of rectangular crop operations that are performed on the image. Cropping is an operation that trims an image so that only the specified area of the original image remains. Each element of crops is formatted as "r1 c1 r2 c2" (quotes for clarity only), where the upper left corner of the area to crop is at row r1, column c1, and the lower right corner is at row r2, column c2. The coordinates are inclusive. The crop operations are performed in the order that they appear in crops, and each one is performed on the most recent version of the image. The constraints will guarantee that all crop operations will be within the boundaries of the image. Return the final cropped image as a String[] in the same format as the original image String[].

    Definition

        
    Class: Crop
    Method: crop
    Parameters: String[], String[]
    Returns: String[]
    Method signature: String[] crop(String[] image, String[] crops)
    (be sure your method is public)
        

    Constraints

    - image will contain between 1 and 50 elements, inclusive.
    - Each element of image will contain between 1 and 50 characters, inclusive.
    - Each element of image will contain exactly the same number of characters.
    - Each element of image will contain only '.' and uppercase 'X' characters.
    - crops will contain between 1 and 10 elements, inclusive.
    - Each element of crops will be formatted as described in the problem statement and no integers within crops will contain extra leading zeros.
    - Within each element of crops, r2 will be greater than or equal to r1 and c2 will be greater than or equal to c1.
    - crops will contain no operations that exceed the boundaries of the image at any time in the cropping process.

    Examples

    0)
        
    {".........",
     "X.XXXXXXX",
     "....X....",
     "........." }
    {"1 0 2 8", "0 0 1 1"}
    Returns: {"X.", ".." }
    The first crop effectively removes the top and bottom rows of the image and results in:

    X.XXXXXXX
    ....X....

    The second crop is then performed relative to the new image:

    X.
    ..
    1)
        
    {"X.X.X.X.X.X.X.X",
     ".X.X.X.X.X.X.X."}
    {"0 0 1 14", "0 0 1 14", "0 0 1 14"}
    Returns: {"X.X.X.X.X.X.X.X", ".X.X.X.X.X.X.X." }
    These crops don't affect the original image at all.
    2)
        
    {".X..X.X.XX.",
     "..X..X...X.",
     "X......X..X",
     ".X....X...X",
     "..XXXX.X.X.",
     "XXX..XXX..X"}
    {"0 0 0 0"}
    Returns: {"." }
    3)
        
    {".X..X.X.XX.",
     "..X..X...X.",
     "X......X..X",
     ".X....X...X",
     "..XXXX.X.X.",
     "XXX..XXX..X"}
    {"1 0 5 9", "0 1 4 8", "0 0 3 5"}
    Returns: {".X..X.", "......", "X....X", ".XXXX." }

    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-08-25 11:04 emu 閱讀(1304) 評論(5)  編輯  收藏 所屬分類: google編程大賽模擬題及入圍賽真題

    評論

    # re: Crop(入圍賽250分真題) 2005-09-29 19:22 huangyi
    看來英文還得加強了 看了半天死活沒看懂
    感覺google的比賽 挺象acm的 又貌似比acm實用一點  回復  更多評論
      

    # re: Crop(入圍賽250分真題) 2005-12-06 15:12 Anson
    把所以得r1,c1相加,得到 newr1,newc1,之后最后一項的r2,c2分別加上newr1,newc1,得到 newr2,newc2,
    最后裁剪出矩形newr1,newc1,newr2,newc2.應該是這樣,是個坐標轉化問題.  回復  更多評論
      

    # re: Crop(入圍賽250分真題) 2005-12-09 15:40 drekar
    Anson的分析正確。

    下面是我的解:

    public class Crop {

     public String[] crop(String[] image, String[] crops) {
      int cropsTimes = crops.length;
      if (cropsTimes == 0)
       return image;

      int MaxRow = image.length;
      int MaxCol = image[0].length();
      
      int x0 = 0;
      int y0 = 0;
      int x1 = MaxRow;
      int y1 = MaxCol;
      for (int i=0; i<cropsTimes; i++) {
       String[] temp = crops[i].split(" ");

       if (i == cropsTimes-1) {
        x1 = x0 + Integer.parseInt(temp[2]);
        y1 = y0 + Integer.parseInt(temp[3]);
       }
       x0 += Integer.parseInt(temp[0]);
       y0 += Integer.parseInt(temp[1]);
      }
      
      String[] result = new String[x1-x0+1];
      for (int i=x0; i<=x1; i++)
       result[i-x0] = image[i].substring(y0, y1+1);
       
      return result;
     }

     public static void main(String[] args) {
      String[] image = { ".X..X.X.XX.", "..X..X...X.", "X......X..X",
        ".X....X...X", "..XXXX.X.X.", "XXX..XXX..X" };
      String[] crops = { "1 0 5 9", "0 1 4 8", "0 0 3 5" };
      
      Crop cp = new Crop();
      
      String[] result = cp.crop(image, crops);
      
      for (int i=0; i<result.length; i++)
       System.out.println(result[i]);

     }

    }
      回復  更多評論
      

    # re: Crop(入圍賽250分真題) 2005-12-11 17:52 小飛俠
    public class test {
    public static String[] crop(String[] image, String[] crops) {
    String[] result, crop;
    int row0, row1, col0, col1, x0, y0, x1, y1, n, i;

    row0 = col0 = 0;
    row1 = image.length - 1;
    col1 = image[0].length() - 1;
    for (i = 0, n = crops.length; i < n; i++) {
    crop = crops[i].split(" ");
    x0 = Integer.parseInt(crop[0]);
    y0 = Integer.parseInt(crop[1]);
    x1 = Integer.parseInt(crop[2]);
    y1 = Integer.parseInt(crop[3]);

    //邊界判斷
    if (x0 < 0 || x0 > x1 || x1 > row1)
    continue;
    if (y0 < 0 || y0 > y1 || y1 > col1)
    continue;

    row1 = row0 + x1;
    col1 = col0 + y1;
    row0 += x0;
    col0 += y0;

    }

    //輸出
    result = new String[row1 - row0 + 1];
    for (i = 0, n = result.length; i < n ; i++) {
    result[i] = image[i+row0].substring(col0, col1+1);
    }

    for (i = 0, n = result.length; i < n ; i++) {
    System.out.println(result[i]);
    }
    return result;
    }

    public static void main(String args[]) {
    String[] image, crops, result;

    image = new String[4];
    crops = new String[2];

    image[0] = new String("X.X.X.X.X.X.X.X");
    image[1] = new String(".X.X.X.X.X.X.X.");
    image[2] = new String(".X.X.X.X.X.X.X.");
    image[3] = new String("X.X.X.X.X.X.X.X");


    crops[0] = new String("1 1 2 3");
    crops[1] = new String("0 0 1 1");

    crop(image, crops);

    }

    }  回復  更多評論
      

    # re: Crop(入圍賽250分真題) 2005-12-12 11:35 emu
    小飛俠的解法好。這是emu 的很笨的解法:
    public class Crop
    {
    public String[] crop(String[] image, String[] crops) {
    String crop = crops[0];
    String[] t = crop.split(" ");
    int r1= Integer.parseInt(t[0],10);
    int c1= Integer.parseInt(t[1],10);
    int r2= Integer.parseInt(t[2],10);
    int c2= Integer.parseInt(t[3],10);
    if(r2>(image.length-1)) r2=(image.length-1);
    if(c2>(image[0].length()-1)) c2=(image[0].length()-1);
    if( r1>0 || c1>0 || r2<(image.length-1) || c2<(image[0].length()-1) ){
    String[] tmpImage = new String[r2-r1+1];
    for(int i=r1;i<=r2;i++)
    tmpImage[i-r1] = image[i].substring(c1,c2+1);
    if(crops.length>1){
    String[] tmpCrops = new String[crops.length-1];
    for(int i=1;i<crops.length;i++) tmpCrops[i-1] = crops[i];
    return crop(tmpImage,tmpCrops);
    }else{
    return tmpImage;
    }
    }else
    return image;
    }
    public static void main(String[] args)
    {
    Crop c = new Crop();
    String[] result = c.crop(
    new String[]{".........","X.XXXXXXX","....X....","........."},
    new String[]{"1 0 2 8", "0 0 1 1"}
    );
    System.out.println(java.util.Arrays.asList(result));

    result = c.crop(
    new String[]{"X.X.X.X.X.X.X.X", ".X.X.X.X.X.X.X."},
    new String[]{"0 0 1 14", "0 0 1 14", "0 0 1 14"}
    );
    System.out.println(java.util.Arrays.asList(result));

    result = c.crop(
    new String[]{".X..X.X.XX.", "..X..X...X.", "X......X..X", ".X....X...X", "..XXXX.X.X.", "XXX..XXX..X"},
    new String[]{"0 0 0 0"}
    );
    System.out.println(java.util.Arrays.asList(result));

    result = c.crop(
    new String[]{".X..X.X.XX.", "..X..X...X.", "X......X..X", ".X....X...X", "..XXXX.X.X.", "XXX..XXX..X"},
    new String[]{"1 0 5 9", "0 1 4 8", "0 0 3 5"}
    );
    System.out.println(java.util.Arrays.asList(result));
    }
    }
      回復  更多評論
      

    主站蜘蛛池模板: 在线观看特色大片免费视频| 久久久久久曰本AV免费免费| 免费特级黄毛片在线成人观看| 亚洲国产成人九九综合| 日韩免费高清大片在线| 亚洲视频在线观看网站| 免费成人福利视频| 亚洲自偷自偷在线成人网站传媒| 日本在线高清免费爱做网站| 久久狠狠爱亚洲综合影院| 成年在线观看免费人视频草莓| 亚洲色大成网站www| 免费日韩在线视频| 一级白嫩美女毛片免费| 亚洲色精品vr一区二区三区| 麻豆精品不卡国产免费看| 亚洲春色另类小说| 免费无码又爽又刺激高潮| 成年大片免费视频播放一级| 亚洲精品无码久久久久去q| 97久久免费视频| 亚洲欧美乱色情图片| 亚洲国产日韩在线观频| 久久久久成人精品免费播放动漫| 亚洲视频在线观看不卡| 精品国产免费观看久久久| h视频免费高清在线观看| 久久亚洲精品中文字幕| 啦啦啦在线免费视频| 国产国产人免费人成成免视频| 亚洲国产精品国自产拍电影| 国产片AV片永久免费观看 | 亚洲国模精品一区| 久草免费手机视频| 亚洲一区二区三区高清不卡 | 免费大片在线观看网站| 国产在线精品免费aaa片| 亚洲AV无码乱码在线观看代蜜桃 | 国产亚洲玖玖玖在线观看| 国产91精品一区二区麻豆亚洲 | 三年片在线观看免费西瓜视频|