codevita封装android组件,CodeVita编程大赛样题

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

样题 1:

On ACube

A solid cube of 10 cm x 250px x10 cm rests on the ground. It has a beetle on it, and some sweethoney spots at various locations on the surface of the cube. The beetlestarts at a point on the surface of the cube, and goes to the honey spots inorder along the surface of the cube.

ProblemDescription

A solid cube of 10 cm x 250px x10 cm rests on the ground. It has a beetle on it, and some sweethoney spots at various locations on the surface of the cube. The beetlestarts at a point on the surface of the cube, and goes to the honey spots inorder along the surface of the cube.

1. Ifit goes from a point to another point on the same face (say X to Y), it goes inan arc of a circle that subtends an angle of 60 degrees at the centre of thecircle

2. Ifit goes from one point to another on a different face, it goes by the shortestpath on the surface of the cube, except that it never travels along the bottomof the cube

The beetle is a student ofCartesian geometry, and knows the coordinates (x, y, z) of all the points itneeds to go to. The origin of coordinates it uses is one corner ofthe cube on the ground, and the z axis points up. Hence, the bottomsurface (on which it does not crawl) is z=0, and the top surface isz=10. The beetle keeps track of all the distances travelled, androunds the distance travelled to two decimal places once it reaches the nextspot, so that the final distance is a sum of the rounded distances from spot tospot.

Input

The first line gives an integerN, the total number of points (including the starting point) the beetle visits

The second line is a set of 3Ncomma separated non-negative numbers, with up to two decimal placeseach. These are to be interpreted in groups of three as the x, y, zcoordinates of the points the beetle needs to visit in the given order.

Output

One line with a number givingthe total distance travelled by the beetle accurate to two decimalplaces. Even if the distance travelled is an integer, the outputshould have two decimal places.

Constraints

None of the points the beetlevisits is on the bottom face (z=0) or on any of the edges of the cube (thelines where two faces meet)

2<=N<=10

Complexity

Complex

TimeLimit

1

Examples

Example 1

Input

3

1,1,10,2,1,10,0,1,9

Output

4.05

Explanation

There are three points visitedby the beetle (N=3). The beetle starts on the top face of the cube (z=10) atpoint (1,1,10) and goes to another point on the same face(2,1,10). Though the straight line distance is 1, it travels on thearc of a circle subtending an angle of 60 degrees at the centre of the circle,and hence travels (2*pi)/6 or 1.05 (note that it rounds the distance at eachleg of the journey). It then travels from (2,1,10) on the face z=10to (0,1,9) on the face x=0 along the surface of the cube. This is a distance of3. The total distance travelled is 1.05+3=4.05. Theoutput is 4.05

Example 2

Input

3

1,1,10,2,1,10,0,5,9

Output

6.05

Explanation

There are three points visitedby the beetle (N=3). The beetle starts on the top face of the cube (z=10) atpoint (1,1,10) and goes to another point on the same face(2,1,10). As before. This distance is 1.05. It thentravels from (2,1,10) on the face z=10 to (0,5,9) on the face x=0 along thesurface of the cube. The shortest distance on the surface of the cube betweenthese points is 5. The total distance travelled is1.05+5=6.05. The output is 6.05.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值