必要准备
要参加比赛,需要一些准备工作要做。
首先,需要注册成为TopCoder成员,这没什么好介绍的,大家填写相关内容就得了,注册网址Registration
其次,下载安装必要的软件-TopCoder Arena(竞技场,古罗马的斗兽场也是这个词),TopCoder Arena是一个纯Java应用程序,它既是Applet也是应用程序,所以需要安装Java运行环境。相关软件的网址ContestAppletProd.jnlp(Java Web Start 方式安装)
再次,启动TopCoder Arena>登录进入,就可以开始参加比赛了。
比赛概况
每年TopCoder都会有几个编程竞赛和锦标赛,参赛者被分成很多小组,进行一个或多个回合有时间限制的比赛。在每个回合,参赛者必须编写代码来解决三个不同难度的问题。你可以在TopCoder Arena里进行编辑,编译和测试。一个典型的问题包含一个必要的方法说明,几段用于描述问题的文字和一个说明性的实例子。在TopCoder Arena里,你可以看到过去真实的问题。下面是一个中等难度的问题:
-----------------------------------------------------------------------
Problem Statement
We want to display a two-color pattern on a rectangular array of pixels, with k of the pixels in the foreground color. We want to choose the pattern so that it minimizes the boundary between the foreground and the background.
The length of the boundary is the number of vertical and horizontal pixel edges that separate a foreground pixel from a background pixel. For example, this picture shows a rectangular array with three rows and six columns that has 5 foreground pixels (indicated by 'X'). The boundary in this case has length equal to 6: the upper left X is adjacent to 1 background pixel, the upper middle X is adjacent to 1, the rightmost X is adjacent to 3, the lower left X is adjacent to 0, and the lower right X is adjacent to 1.
- - - - - -
X X X - - -
X X - - - -
Create a class Coherence that contains the method minBndry that takes three int inputs, numRows (the height of the array), numCols (the width of the array), and k (the number of foreground pixels), and returns the length of the minimum possible boundary.
Definition
Class:
Coherence
Method:
minBndry
Parameters:
int, int, int
Returns:
int
Method signature:
int minBndry(int numRows, int numCols, int k)
(be sure your method is public)
Constraints
-
numRows is between 1 and 30 inclusive
-
numCols is between 1 and 30 inclusive
-
k is between 0 and numRows*numCols inclusive
Examples
0)
6
6
5
Returns: 5
X X X - - -
X X - - - -
- - - - - -
- - - - - -
- - - - - -
- - - - - -
The upper right foreground pixel has 2 boundary edges, the bottom right one has 2 boundary edges, and the bottom left one has 1 boundary edge.
1)
4
6
16
Returns: 4
X X X X - -
X X X X - -
X X X X - -
X X X X - -
2)
9
5
0
Returns: 0
---------------------------------------------------------------------
参考资料
How Google Searches -- For Talent
Interview with Jack Hughes
General TopCoder Arena Usage / Getting Started
没有评论:
发表评论