How Many Points of Intersection? |
We have two rows. There are a dots on the top row and b dots 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 included in our count; we can allow more than two line segments to intersect on those two rows. Given the value of a and b, 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 and b = 3. This figure illustrates that P(2, 3) = 3.
![\epsfbox{p10790.eps}](http://uva.onlinejudge.org/external/107/p10790.jpg)
Input
Each line in the input will contain two positive integers a ( 0 < a20000) and b ( 0 < b
20000). Input is terminated by a line where both a and b are zero. This case should 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 of 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-bit signed integers.
Sample Input
2 2 2 3 3 3 0 0
Sample Output
Case 1: 1 Case 2: 3 Case 3: 9
画了图找规律没找到,无奈可耻的百度了......
摘自别人的bolg
:因为一个交叉点的存在依赖于两条直线,四个顶点,因此用顶端中a个数字选出2个顶点共有a*(a-1)/2,同理于b。。
自己想歪了老是在每一条线上的交点数然后求和
结论总是显而易见的,不是自己想出来的一点Ac的喜悦也没有╮(╯▽╰)╭
#include <stdio.h>
int main()
{long long a,b;
int sum=0;
while (scanf("%lld%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;
}