How many points of intersection? |
We have two rows. There areADots on the top row and
BDots on the bottom row. we draw line segments connecting every dot on the top row with every dot on the bottom row. the dots are arranged in such a way that the number of internal intersections among the line segments is
Maximized. to achieve this goal we must not allow more than two line segments to intersect in a point. the intersection points on the top row and the bottom are not supported in our count; we can allow more than two line segments to intersect on those two rows.
Given the valueAAndB, Your task is to compute
P(A,B), The number of intersections in between the two rows. For example, in the following figure
A= 2 andB= 3. This figure extends strates that
P(2, 3) = 3.
Input
Each line in the input will contain two positive integersA(
0 <A20000) and
B(0 <B20000). input is terminated by a line where both
AAndBAre Zero. This case shocould not be processed. You will need to process at most 1200 sets of inputs.
Output
For each line of input, print in a line the serial of output followed by the value
P(A,B). Look at the output for sample input for details. You can assume that the output for the test cases will fit in
64-bitSigned integers.
Sample Input
2 22 33 30 0
Sample output
Case 1: 1Case 2: 3Case 3: 9
I did not find the pattern, but the shameful Baidu ......
From others' Bolg
: Because the existence of an intersection depends on two straight lines, four vertices, so use a number in the top to select two vertices total a * (A-1)/2, the same as B ..
I am confused. I always pay points on each line and sum them.
The conclusion is always obvious, and the joy of AC is not the joy of success.
# Include <stdio. h>
Int main ()
{Long A, B;
Int sum = 0;
While (scanf ("% LLD", & A, & B ))
{++ Sum;
If (a + B = 0) break;
Else printf ("case % d: % LLD \ n", sum, A * (A-1) * B * (b-1)/4 );
}
Return 0;
}