空军

skyiv studio

导航

Google中国编程挑战赛第一轮

Google™ Code Jam 中国编程挑战赛第一轮2005年12月19日21时在线举行,3道难度不同的题目,分数各为250、500和1000,难度高的题目分数较高,编码时间75分钟。

Round 1 Problem 250 Statement

You want to buy two neighboring tickets 
in the first row of the theater so that one of the tickets is as far from the aisles as possible.
You will be given a String describing the first row of the theater where 
'.' represents an empty seat and 'X' represents an occupied seat. Your task is to return the index (from 0) of the empty seat that is furthest from the aisles (the two ends of the String) and is also next to an empty seat. If there are multiple possible seats, return the one with the smallest index. Return -1 if there are no seats that satisfy your requirements.
Definition

Class:
TheaterVisit
Method:
chooseSeat
Parameters:
string
Returns:
int
Method signature:
int chooseSeat(string row)
(be sure your method 
is public)

Constraints
-
row will contain between 
1 and 50 characters, inclusive.
-
Each character 
in row will be either '.' or 'X'.

Examples

0)

"....."
Returns: 
2
You can buy either tickets with indexes 
1 and 2 or tickets with indexes 2 and 3.

1)

"......"
Returns: 
2

2)

"..X..."
Returns: 
3
You should buy tickets with indexes 
3 and 4.

3)

".X.X..."
Returns: 
4

4)

"X.XX.X"
Returns: 
-1

5)

".."
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.

 

Round 1 Problem 500 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.

 

Round 1 Problem 1000 Statement

We have a sequence of integers, and we would like to remove all duplicate elements from 
this sequence. There may be multiple ways to perform this task. For example, given the sequence { 1213 }, we could end up with either { 123 } or { 213 } as the remaining sequence, depending on which duplicate 1 we remove from the original sequence. For this problem, we want to return the lexicographically first of of all possible remaining sequences. A sequence S1 comes before sequence S2 lexicographically if and only if S1 has a smaller value than S2 at the lowest index at which the two sequences differ (so, for example, { 123 } comes before { 231 }).
You will be given a 
int[] sequence. Return a int[] containing the sequence after all the duplicates are removed. See the examples for further clarification.

Definition

Class:
HardDuplicateRemover
Method:
process
Parameters:
int[]
Returns:
int[]
Method signature:
int[] process(int[] sequence)
(be sure your method 
is public)

Constraints
-
sequence will have between 
1 and 50 elements, inclusive.
-
Each element of sequence will be between 
1 and 1000, inclusive.

Examples

0)

{
565165}
Returns: {
165 }
There are six different ways to remove duplicates (remaining numbers are marked by 
'*'):
*5*6,  5*1,  6,  5},
*5,  6,  5*1*6,  5},
{  
5*6*5*1,  6,  5},
{  
5,  6*5*1*6,  5},
{  
5*6,  5*1,  6*5},
{  
5,  6,  5*1*6*5}.

The last variant 
is the lexicographically first.

1)

{
324244}
Returns: {
324 }

2)

{
666666}
Returns: {
6 }

3)

{
132423}
Returns: {
1243 }

4)

{
5415}
Returns: {
415 }

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 11:03  空军  阅读(1265)  评论(3编辑  收藏  举报