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.

Input

Each line in the input will contain two positive integers a ( 0 < a20000) and b ( 0 < b20000). 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

有两条线,输入第一条线上点n个,和第二条线上点m个。 输出如果把n,m上每两点都相连,交点有几个。。

解法:加入n有3个,m有3个。假设从m这条线找点去连接m, 第一点连过去3条一个交点都没。第二点连过去。m2连n1的时候将会交第一点连过去的m1n2、m1n3,m2连n2的时候将会交第一点和第二点连过去的m1n3。。为1 + 2;第三点连过去将会交第一点和第二点连过去的几条。为 2 * (1 + 2)。。

找到规律可以推出。。交点个数x为,求出一个sum = (1 + 2 + ... + n - 1)。 然后x = sum * 1 + sum * 2 + ... + m - 1;

输出x。

代码:

#include <stdio.h>
#include <string.h> int a, b; int main()
{
int t = 1;
while (scanf("%d%d", &a, &b) != EOF && a || b)
{
long long num1 = 0;
long long sum = 0;
for (int i = 1; i < a; i ++)
num1 += i;
for (int i = 1; i < b; i ++)
sum += num1 * i;
printf("Case %d: %lld\n", t ++, sum);
}
return 0;
}

UVA 10790 How Many Points of Intersection?的更多相关文章

  1. UVA 10790 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 segment ...

  2. UVA 10790 (13.08.06)

     How Many Points of Intersection?  We have two rows. There are a dots on the toprow andb dots on the ...

  3. How Many Points of Intersection?

    uva10790:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_prob ...

  4. UVA题目分类

    题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...

  5. Volume 1. Maths - Misc

    113 - Power of Cryptography import java.math.BigInteger; import java.util.Scanner; public class Main ...

  6. Coursera Robotics系列课心得

    Robotics Perception Professor Kostas and Jianbo Shi week 1: camera model 凸透镜成像原理:凸透镜焦点与焦距是固定的,这是物理性质 ...

  7. [算法]A General Polygon Clipping Library

    A General Polygon Clipping Library Version 2.32    http://www.cs.man.ac.uk/~toby/alan/software/gpc.h ...

  8. [非官方]ArcGIS10.2 for Desktop扩展工具包——XTools Pro

    XTools Pro 是一套为ArcGIS平台设计的矢量空间分析. 形状转换和表管理扩展工具,大大增强了 ArcGIS 的功能,使用该工具能够提高 ArcGIS 用户的效率和性能. XTools Pr ...

  9. Circles and Pi

    Circles and Pi Introduction id: intro-1 For as long as human beings exist, we have looked to the sky ...

随机推荐

  1. 让PHP跑在Mac OS X中

    MacBook入手了,配置工作环境,首先得让Mac OS支持PHP.不管你是采用集成的开发环境,比如XAMPP for Mac OS X,还是采用Mac OS中自带的Apache和PHP,甚至自己重新 ...

  2. 这样就算会了PHP么?-3

    关于循环,IF,WHILE.... <?php $month = date("n"); $today = date("j"); if ($today &g ...

  3. POJ3683 Falsita

    http://poj.org/problem?id=3683 思路:2-SAT,输出任意一组方案,O(m+n) #include<cstdio> #include<iostream& ...

  4. MyBatis里json型字段到Java类的映射

    一.简介 我们在用MyBatis里,很多时间有这样一个需求:bean里有个属性是非基本数据类型,在DB存储时我们想存的是json格式的字符串,从DB拿出来时想直接映射成目标类型,也即json格式的字符 ...

  5. SQL SERVER 自带系统存储过程分类

    目录存储过程 用于实现 ODBC 数据字典功能,并隔离 ODBC 应用程序以使其不受基础系统表更改的影响. 变更数据捕获存储过程 用于启用.禁用.或报告变更数据捕获对象. 游标存储过程 用于实现游标变 ...

  6. HDU4893--Wow! Such Sequence! (线段树 延迟标记)

    Wow! Such Sequence! Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Oth ...

  7. MVC中使用EF(2):实现基本的CRUD功能

    MVC中使用EF(2):实现基本的CRUD功能 By  Tom Dykstra |July 30, 2013 Translated by litdwg   Contoso University示例网站 ...

  8. DHTML【8】--CSS

    在讲HTML时说过,有个Style标签是在CSS里用的,是的,在HTML中添加CSS样式必须要用到Style,在标签里单独定义标签属性时用的是Style属性.上一节我们也说过,先不用管那个Style标 ...

  9. IIS PHP 配置 问题总结

    今天帮助朋友解决一个IIS配置PHP的问题.大概是这样子的. IIS 与 PHP配置好了之后不能訪问,出现例如以下错误: HTTP 错误 500.19 - Internal Server Error ...

  10. GDB实用的调试工具

    GDB它是GNU Debuger缩写,它是GNU发表了unix通过应用程序调试工具. 它被广泛应用于在各种各种生产内部应用.GDB和所有的调试工具经常使用相同的,其主要特点是:监视变量的值.设置断点及 ...