How Many Points of Intersection?
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
a ( 0 < a20000) and b ( 0 < b20000). Input is terminated by a line where both a and b
Output
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 22 3 3 3 0 0
Sample Output
Case 1: 1Case 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;
}
标签:int,segments,two,long,Points,UVA,line,Intersection,row From: https://blog.51cto.com/u_14834528/6210680