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(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-bitsigned integers.

Sample Input 

2 2
2 3
3 3
0 0

Sample Output 

Case 1: 1
Case 2: 3
Case 3: 9

题目其实比较简单,主要归纳出点数等于n*(n-1)*m*(m-1)/4即可
代码如下:
#include <stdio.h>
int main(void)
{
    int n,m,i;
    i=1;
    while(scanf("%d%d",&n,&m)!=EOF&&(n||m))
     printf("Case %d: %lld\n",i++,(long long)n*m*(n-1)*(m-1)/4);
    return 0;
}


  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-bitsigned integers.

Sample Input 

2 2
2 3
3 3
0 0

Sample Output 

Case 1: 1
Case 2: 3
Case 3: 9

内容概要:本文针对火电厂参与直购交易挤占风电上网空间的问题,提出了一种风火打捆参与大用户直购交易的新模式。通过分析可再生能源配额机制下的双边博弈关系,建立了基于动态非合作博弈理论的博弈模型,以直购电价和直购电量为决策变量,实现双方收益均衡最大化。论文论证了纳什均衡的存在性,并提出了基于纳什谈判法的风-火利益分配方法。算例结果表明,该模式能够增加各方收益、促进风电消纳并提高电网灵活性。文中详细介绍了模型构建、成本计算和博弈均衡的实现过程,并通过Python代码复现了模型,包括参数定义、收益函数、纳什均衡求解、利益分配及可视化分析等功能。 适合人群:电力系统研究人员、能源政策制定者、从事电力市场交易的工程师和分析师。 使用场景及目标:①帮助理解风火打捆参与大用户直购交易的博弈机制;②为电力市场设计提供理论依据和技术支持;③评估不同政策(如可再生能源配额)对电力市场的影响;④通过代码实现和可视化工具辅助教学和研究。 其他说明:该研究不仅提供了理论分析,还通过详细的代码实现和算例验证了模型的有效性,为实际应用提供了参考。此外,论文还探讨了不同场景下的敏感性分析,如证书价格、风电比例等对市场结果的影响,进一步丰富了研究内容。
### 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、付费专栏及课程。

余额充值