Time limit: 3.000 seconds
http://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=1731
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.
Each line in the input will contain two positive integers a ( 0 < a20000) and b ( 0 < b20000). 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.
For each line of input, print in a line the serial of output followed by the value ofP(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.
2 2 2 3 3 3 0 0
Case 1: 1 Case 2: 3 Case 3: 9
题意:
如图,找交点(不存在多于两条线交于一点),此题是这道题的简单版。
思路:
每个点都由两条线上的两个点得到,所以ans=C(a,2) * C(b,2)=ab(a-1)(b-1)/4,最大值(精确)为:3.99960001*1016
用long long搞定。
完整代码:
#include <cstdio> int main() { int a, b, t = 1; while (scanf("%d%d", &a, &b), a) printf("Case %d: %lld\n", t++, (long long)a * b * (a - 1) * (b - 1) / 4); return 0; }