UVA How Many Points of Intersection?

本文介绍了一种计算由上下两排点连线形成的交点数量的方法。通过数学公式快速得出任意两排点(a, b)连线后形成的内部交点总数。输入为两排点的数量,输出则为交点数。

  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(ab), 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}

Input 

Each line in the input will contain two positive integers a ( 0 < a$ \le$20000) and b ( 0 < b$ \le$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(ab). 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



Problem setter: Md. Bahlul Haider
Special Thanks: Shahriar Manzoor

Miguel Revilla 2004-12-10




    题意:给出两个数字n,m分别代表上和下有多少个点,求这些点连成的线会有多少个交点。输出。。。找到之间的关系就可以根据式子求出来。

#include<stdio.h>
#include<string.h>
#include<stdlib.h>

int main()
{
    long long int n,m;
    int k = 0;
    while(scanf("%lld%lld",&n,&m)!=EOF)
    {
        k++;
        if(n == 0 && m == 0)
        {
            break;
        }
        long long int sum = 0;
        sum = (n-1)*n/2 * (m-1)*m/2;
        printf("Case %d: %lld\n",k,sum);
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

叶孤心丶

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值