社区登陆 用户名: 密码: 忘记密码 注册 游客参观
首页  |  留学  |  移民  |  院校  | 海外生活 | 外语考试 | 出行指南 | 有奖征稿 | About Tigtag
社区  |  论坛  |  相册  |  博客  | 结伴同行 | 活动看板 | 专题专访 | 专家专栏 | 广告服务
您现在的位置: 滴答网 >> 海外生活 >> 海外就业 >> 求职技巧 >> 文章正文
英国IT业找工作面试题
滴答网 http://www.tigtag.com 2007-1-1 文学城

友情提示 递归算法简单但速度慢

请在两天内作答。

Elixent’s Placement Problem

Write a program (in C or C++) that places an arbitrary netlist represented as a directed graph G = (V, E) with vertices V and edges E over a 1D array of N processors:

p_1 p_2 p_3 ... p_N

Each vertex should be placed on a single processor and no processor can hold more than one vertex (you can assume there are as many processors as you need). For example vertex v_1 might be placed on processor p_1 and v_2 on p_4:

-----------

v_1 v_2

p_1 p_2 p_3 p_4 ... p_N

If there were an edge between v_1 and v_2, then it would automatically be routed along the 'shortest' path between the respective processors (as shown). The distance of this edge is 4-1 = 3. The cost of an overall placement is simply the sum of all edge distances. Placements with lower cost as these are 'better', but the computational complexity of your placement algorithm also matters (you might need to place very large netlists).

The graph should be read in from standard input in the form

10

1,3 2,4 4,5 ...

In the first line '10' gives the number of vertices, the second line defines which pairs of vertices are connected by edges (the first vertex is numbered 1).

The program should output the placement cost and results on standard output, giving the vertex allocated to each processor in turn, or - if a processor is empty. For example:

21

2 4 - 3 1 ...

would mean the placement cost was 21 and vertex 2 was allocated to p_1, 4 to p_2, p_3 was empty, 3 to p_4 etc.

You might optionally want to consider a more complex problem with a non-linear notion of cost that accounts for congestion in the case when there are multiple overlapping edges. For example, the cost function could be redefined as the sum of the squares of the number of edges spanning each pair of neighbouring processors. In this case the following configuration of edges:

--- ---

-----------

p_1 p_2 p_3 p_4 p_5 .... p_N

would have cost:

1 edge spanning p_1 to p_2

2^2 edges spanning p_2 to p_3

1 edge spanning p_3 to p_4

1 edge spanning P_4 to p_5

---

7

Again, lower cost is better, but computational complexity also matters.

阅读:

相关文章

发表评论】【推荐给朋友】【打印此文】【关闭窗口