The Happy Triangles

Time Limit: 1000ms
Memory Limit: 32768KB
This problem will be judged on HDU. Original ID: 4682
64-bit integer IO format: %I64d      Java class name: Main

Description

Alice has a toy, which was made up by two parts. The first part is a frame consisting of one horizontal stick and two vertical sticks. The distance between the two vertical sticks is R. And the horizontal stick is long enough. The second part of her toy is N triangles. These triangles can be fastened on the frame with one of their edges on the horizontal stick. Once they are fastened, they can slide along the horizontal stick. And magically, they can overlap each other. (See pic 1)
Now, Alice wants to maximize the total area covered by these triangles between the two vertical sticks.
Note :
1. The triangles DON’t have to be totally between the two vertical sticks. But the area out of the two sticks should not be taken into consideration.
2. These triangles are either acute triangle or right triangle.

Input

There are several cases. The first line of the input is a single integer T. (T<=100)
For each case, the first line contains two integers N ,R. (N<=1000,R<=100000)
The next N lines, each line contains three integer a,b,c , which stand for the lengths of three edges of the i-th triangle.
(0<a<=b<=c<100000,a2+b2>=c2).

Output

For each case, output "Case #X: " first, X is the case number starting from 1. Then output the maximum area Alice can use these triangles to cover between the two sticks, round to 3 decimal places.

Sample Input

2 
1 5
3 4 5
2 4
3 4 5
3 4 5

Sample Output

Case #1: 6.000
Case #2: 10.667

Source

Language: 
Theme: 
Share Code? 

Powered by NB231 | Current Style: .