zoukankan      html  css  js  c++  java
  • Google Code Jam中国挑战赛:入围赛题目1

    Problem Statement

        

    You are given a string disk representing the clusters on a disk. An 'X' represents a used cluster, and a '.' represents an available cluster. You are also given an int size representing the size, in clusters, of a file waiting to be written to disk. A file can only be stored in clusters not already being used.

    Return the minimum number of groups of consecutive clusters needed to store the file on the disk. (The disk does not wrap around at the end.) Return -1 if the disk does not have enough space available to store the file.

    Definition

        
    Class: DiskClusters
    Method: minimumFragmentation
    Parameters: string, int
    Returns: int
    Method signature: int minimumFragmentation(string disk, int size)
    (be sure your method is public)
        

    Constraints

    - disk will contain between 1 and 50 characters, inclusive.
    - Each character of disk will be 'X' or '.'.
    - size will be between 1 and 50, inclusive.

    Examples

    0)
        
    "."
    2
    Returns: -1
    We can't fit the file on the disk.
    1)
        
    ".XXXXXXXX.XXXXXX.XX.X.X."
    6
    Returns: 6
    There is only ever one cluster together, so all six clusters are separated.
    2)
        
    "XX..XX....X.XX........X...X.XX...XXXX..XX...XXXXX."
    12
    Returns: 2
    We fit eight clusters together, and four clusters together.
    3)
        
    ".X.XXXX.......XX....X.....X............XX.X.....X."
    20
    Returns: 3
    4)
        
    "....X...X..X"
    11
    Returns: -1

    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.

  • 相关阅读:
    如何加速JavaScript 代码
    以Kafka Connect作为实时数据集成平台的基础架构有什么优势?
    Java多线程开发系列之一:走进多线程
    java运行环境和运行机制
    C#先序遍历2叉树(非递归)
    Java 之 List<T> 接口的实现:ArrayList
    string.split() 解读---------->从java 和C#的角度剖析
    究竟什么是语法糖呢
    Eclipse 恢复删除的文件
    Notepad++自动刷新文本
  • 原文地址:https://www.cnblogs.com/whitewin/p/295765.html
Copyright © 2011-2022 走看看