Uva 10790 How Many Points of Intersection?

 How Many Points of Intersection? 

We have two rows. There are a dots on the toprow 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. Thiscase should not be processed. You will need to process at most 1200 sets of inputs.

Output 

For each line of input, printin a line the serial of output followed by the value of P(a, b). Look atthe 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


题目大意:如果上面有a个点,下面有b个点,叫你计算交点的个数。

那么相交点的数目为:a*(a-1)*b*(b-1)/4;

这道题就是一道纯公式题目,数学如果学好来,然后公式推导出来,这道题目就AC来,注意题目要求说的要用long long int;



#include<stdio.h>
#include<math.h>
#include<iostream>
using namespace std;
int main() {
	long long a,b;
	long long sum;
	int t=1;
	while( cin >>a >>b ) {
		if(a==0 && b==0)
			break;
		sum =a*(a-1)*b*(b-1)/4; 
		cout<<"Case "<<t++<<": "<< sum <<endl;
	}

	return 0;
}


### Java Sets.intersection 方法的功能与用法 `Sets.intersection` 是 Guava 库中的一个方法,用于计算两个集合的交集。该方法返回一个新的集合,其中包含两个输入集合中共有的元素[^3]。 以下是 `Sets.intersection` 的详细说明和使用示例: #### 方法签名 ```java public static <E> Set<E> intersection(Set<? extends E> set1, Set<? extends E> set2) ``` - 参数: - `set1`:第一个集合。 - `set2`:第二个集合。 - 返回值:返回一个新的不可变集合,表示两个集合的交集。 #### 注意事项 - 返回的集合是不可变的(immutable),因此不能对其进行修改操作。 - 如果任意一个集合为空,则返回空集合。 - 输入集合可以是任意类型的集合,但返回的交集是一个不可变集合。 #### 使用示例 以下代码展示了如何使用 `Sets.intersection` 计算两个集合的交集: ```java import com.google.common.collect.Sets; import java.util.HashSet; import java.util.Set; public class Main { public static void main(String[] args) { // 创建两个集合 Set<Integer> set1 = new HashSet<>(); set1.add(1); set1.add(2); set1.add(3); Set<Integer> set2 = new HashSet<>(); set2.add(2); set2.add(3); set2.add(4); // 计算交集 Set<Integer> intersection = Sets.intersection(set1, set2); // 输出结果 System.out.println("Set1: " + set1); System.out.println("Set2: " + set2); System.out.println("Intersection: " + intersection); // 输出 [2, 3] } } ``` 在上述示例中: - `set1` 包含 `{1, 2, 3}`。 - `set2` 包含 `{2, 3, 4}`。 - 调用 `Sets.intersection(set1, set2)` 后,返回的结果为 `{2, 3}`,这是两个集合的交集。 #### 性能特点 - `Sets.intersection` 的性能取决于输入集合的实现方式。如果输入集合是基于哈希表的(如 `HashSet` 或 `LinkedHashSet`),则交集计算的时间复杂度接近 O(n)。 - 如果输入集合是排序集合(如 `TreeSet`),则时间复杂度可能更高。 #### 与其他库的对比 与 C++ 中的 `set_intersection` 不同,Java 的 `Sets.intersection` 返回的是一个不可变集合,而 C++ 的 `set_intersection` 将结果存储到目标容器中[^2]。 --- ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值