首页 > 其他 > 详细

UVA10790 How Many Points of Intersection?【组合】

时间:2019-02-18 10:10:11      阅读:216      评论:0      收藏:0      [点我收藏+]

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.
技术分享图片
Input
Each line in the input will contain two positive integers a (0 < a ≤ 20000) 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

问题链接UVA10790 How Many Points of Intersection?
问题简述:(略)
问题分析
????如图,找交点,不存在多于两条线相交于一点。
????每个交点都由两条线上的两个点得到,所以结果为C(a,2)*C(b,2)=ab(a-1)(b-1)/4。
程序说明:(略)
参考链接:(略)
题记:(略)

AC的C++语言程序如下:

/* UVA10790 How Many Points of Intersection? */

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int caseno = 0;
    long long a, b;
    while (scanf("%lld%lld", &a, &b) && (a || b))
        printf("Case %d: %lld\n", ++caseno, a * b * (a - 1) * (b - 1) / 4);

    return 0;
}

UVA10790 How Many Points of Intersection?【组合】

原文:https://www.cnblogs.com/tigerisland45/p/10393631.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!