CodeVita编程大赛样题
code吧
全部回复
仅看楼主
level 1
It can be shown that every right angle triangle with integer sides has at least one side of even length. There
are no right angled isosceles triangles with integer side lengths, since the square root of 2 is irrational.
Consider the right angled triangle with sides 3, 4, 5. This is almost isosceles. Let us call a right angled
triangle with side lengths x, x + 1, y an Almost Isosceles Right Angled triangle – AIRA for short. Such
triangles are also called Nearly Isosceles Right Angled triangles. The first two triangles can be computed
easily:
(3, 4, 5), (20, 21, 29)
The hypotenuse an of these triangles maybe computed by the recurrence relation
a0=1,b0=2
an=an1+
2bn1,
bn=2an+bn1
A factor of a positive integer is a positive integer which divides it completely without leaving a remainder.
For example, for the number 12, there are 6 factors 1, 2, 3, 4, 6, 12. Every positive integer k has at least two
factors, 1 and the number k itself.
The objective of the program is to find the number of factors of the even side of the AIRA that is larger than
a given number
Input
The input is a single number N
Output
The number of factors of the even side of the smallest AIRA which has an even side greater than N
Constraints
The even side is less than 5000000
Example 1
Input
15
Output
6
Explanation
The smallest AIRA that has an even side greater than 15 is (20,21,29). The even side is 20, and its factors are
(1,2,4,5,10,20), a total of 6 factors. The output is 6
Example 2
Input
100
Output
16
8/29/2017 Almost Isosceles Right Triangles
http://r.tcscodevita.com/CodevitaReports/questions/zone2/Almost%20isosceles%20Right%20Triangles%20Murali.html 2/2
Explanation
The smallest AIRA which has the even side greater than 100 is (119,120,169). The even side is 120, and it
has (1,2,3,4,5,6,8,10,12,15,20,24,30,40,60,120). As there are 16 factors, the output is 16.
2018年11月09日 07点11分 1
level 1
样题 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.
2019年09月11日 02点09分 2
1