<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

    ???? You want to send a group of salespeople from location 0 to location 1, but no two of them can travel through the same location (other than 0 and 1). This removes the possibility of trying to sell a customer the same product twice. Character j of element i (both 0-based) of adj denotes whether locations i and j are connected by a symmetric link ('1' for connected, '0' otherwise). Return the greatest number of salespeople that can be sent. The constraints will guarantee that locations 0 and 1 do not share a link.

    Definition

    ????
    Class: SalesRouting
    Method: howMany
    Parameters: String[]
    Returns: int
    Method signature: int howMany(String[] adj)
    (be sure your method is public)
    ????

    Constraints

    - adj will contain between 3 and 12 elements, inclusive.
    - Each element of adj will contain exactly N characters, where N is the number of elements in adj.
    - Each character in adj will be '0' (zero) or '1' (one).
    - Character i of element j of adj will be the same as character j of element i.
    - Character i of element i of adj will be '0'.
    - Character 1 of element 0 of adj will be '0'.

    Examples

    0)
    ????
    {
    "001",
    "001",
    "110"
    }
    Returns: 1
    We can send a single salesperson from location 0 to location 2, and finally to location 1.
    1)
    ????
    {
    "0010",
    "0010",
    "1100",
    "0000"
    }
    Returns: 1
    Same as before, but now there is an isolated location 3.
    2)
    ????
    {
    "001100",
    "000001",
    "100010",
    "100010",
    "001101",
    "010010"
    }
    Returns: 1
    The only location that is directly connected to location 1 is 5, so only 1 salesperson can be sent.
    3)
    ????
    {
    "001111",
    "001111",
    "110000",
    "110000",
    "110000",
    "110000"
    }
    Returns: 4
    4)
    ????
    {
    "00000",
    "00000",
    "00000",
    "00000",
    "00000"
    }
    Returns: 0

    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:19 emu 閱讀(2048) 評論(4)  編輯  收藏 所屬分類: google編程大賽模擬題及入圍賽真題

    評論

    # re: 250分模擬題 SalesRouting 2006-09-05 19:29 frog
    public class SalesRouting {

    public int howMany(String[] adj) {
    int rowCount = adj.length;
    int cellCount = adj[0].length();
    int[] m = new int[cellCount];
    //先看看Location0&1有沒有直接連同的,就是只通過一個Location就到
    //等于2的就是可行的通道
    for(int i=2; i<cellCount; i++){
    if(adj[0].charAt(i) == '1')
    m[i] += 1;
    if(adj[1].charAt(i) == '1')
    m[i] += 1;
    }
    //只搜索右上的三角,用m[]表示連通狀態(tài),現(xiàn)在m是Location0&1的連通狀態(tài)
    //0表示同0&1的不連通,1表示連通,2表示有通路。
    //用m1表示剩下的Location的連通狀態(tài)
    for(int j=2; j<rowCount; j++){
    //for(int k=0; k<rowCount; k++)
    // System.out.print(m[k]+" ");
    //System.out.println(" ");
    //這里判斷m[]==1非常重要,
    //m[]==0就是集合不連通,m[]==2就是已經(jīng)連通,不需要再判斷了
    if(m[j] == 1){
    for(int i=j; i<cellCount; i++){
    if((adj[j].charAt(i) == '1') && (m[i] != 2)){
    m[i]++;
    }
    }
    }
    }

    //計數(shù)
    int result = 0;
    for(int i=2; i<cellCount; i++){
    if(m[i] == 2)
    result++;
    }

    return result;
    }

    public static void main(String[] args) {
    SalesRouting sr = new SalesRouting();

    int result = sr.howMany(new String[]{"001","001","110"});
    System.out.println(result);
    result = sr.howMany(new String[]{"0010","0010","1100","0000"});
    System.out.println(result);
    result = sr.howMany(new String[]{"001100","000001","100010","100010","001101","010010"});
    System.out.println(result);
    result = sr.howMany(new String[]{"001111","001111","110000","110000","110000","110000"});
    System.out.println(result);
    result = sr.howMany(new String[]{"00000","00000","00000","00000","00000"});
    System.out.println(result);
    }
    }   回復(fù)  更多評論
      

    # re: 250分模擬題 SalesRouting 2006-09-05 19:30 frog
    500合1000的還沒做出來,
    1000的我感覺好難,不知有誰已經(jīng)成功了  回復(fù)  更多評論
      

    # re: 250分模擬題 SalesRouting 2006-09-05 19:53 bood
    500的用DP求出所有子串是否回文即可
    1000的沒做出來,不過看到有人直接用公式2^(a+b)+2^c次……汗
    frog我倒是250的看不懂你的解法,這樣肯定能保證最大么?  回復(fù)  更多評論
      

    # re: 250分模擬題 SalesRouting 2008-07-14 22:08 mabusyao
    package salesRouting;

    public class SalesRouting {

    public static int howMany(String[] adj) {
    matrix = new int[adj.length][adj[0].length()];
    flags = new int[adj.length];

    for(int i = 0; i < adj.length; i++) {
    flags[i] = 0;
    for(int j = 0; j < adj[0].length(); j++) {
    matrix[i][j] = adj[i].charAt(j) - 48;

    }
    }

    return iterate(0);
    }

    private static int[][] matrix;
    private static int[] flags;
    private static int iterate(int index) {
    int result = 0;
    if(index == 1) {
    System.out.print(index+ " ");
    return 1;
    }

    int next = 1;
    while(next < matrix.length) {
    if(matrix[index][next] == 1 && flags[next] == 0 && flags[index] == 0) {
    if(index != 0 && index != 1) flags[index] = 1;
    int success = iterate(next);
    if (success == 1) {
    if(index == 0) {
    System.out.println(0 + " ");
    } else System.out.print(index+ " ");
    result++;
    }else flags[index] = 0;
    }
    next++;
    }
    return result;
    }
    }



    到底該怎么保證最大呢? 我找了個例子:
    String[] str={"001100","000011","100110","101001","011000","010100"};

    想了半天沒有想出來該怎么保證結(jié)果是最大。  回復(fù)  更多評論
      

    主站蜘蛛池模板: 精品韩国亚洲av无码不卡区| 一级毛片a免费播放王色| 大地资源网高清在线观看免费 | 天堂亚洲免费视频| 免费在线一级毛片| 污视频网站在线观看免费| 天堂亚洲免费视频| 一区二区三区免费看| 亚洲中文字幕无码专区| 成人妇女免费播放久久久| 亚洲人成伊人成综合网久久久 | 亚洲AV成人噜噜无码网站| 91网站免费观看| 狠狠色伊人亚洲综合网站色 | a级毛片无码免费真人| 亚洲AV日韩综合一区| 全黄a免费一级毛片人人爱| 一个人免费观看www视频| 国产V亚洲V天堂无码| 95老司机免费福利| 亚洲午夜无码久久久久小说| 日韩精品电影一区亚洲| 日本在线免费播放| 四虎影视永久免费观看地址| 国产亚洲精品欧洲在线观看| 中文字幕人成人乱码亚洲电影| 在线观看人成视频免费无遮挡 | 亚洲精品视频在线看| 一个人看的www免费视频在线观看| 久久99亚洲网美利坚合众国| 最近中文字幕免费mv视频8| 免费无遮挡无码视频在线观看| 亚洲成在人线av| 最近中文字幕mv免费高清视频7| 国产精品亚洲va在线观看| 亚洲精品国产美女久久久| 18禁网站免费无遮挡无码中文 | xxxxx做受大片在线观看免费| 亚洲va在线va天堂va不卡下载| 好爽…又高潮了毛片免费看 | 亚洲国产精品张柏芝在线观看|