Fork me on GitHub

Uva 10790 - How Many Points of Intersection?

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}

 

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(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 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
 
复制代码
#include<stdio.h>
#include<string.h>

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

解题思路:

 

posted @   Gifur  阅读(271)  评论(0编辑  收藏  举报
编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?
TOP
点击右上角即可分享
微信分享提示