Google中國編程挑戰賽第一輪Room18第二題

來源:互聯網
上載者:User
文章目錄
  • Problem Statement
  • Definition
  • Constraints
  • Examples
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 vector <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: vector <int>
Returns: int
Method signature: int cover(vector <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.

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.