How Many Points of Intersection? 

We have two rows. There are a dots on the toprow andb 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 computeP(a, b), the number of intersections in between the two rows. For example, in the following figurea = 2 and b = 3. This figure illustrates thatP(2, 3) = 3.

Input

Each line in the input will contain two positive integers a(0 <a20000) andb (0 < b20000).Input is terminated by a line where botha 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 ofP(a, b). Look atthe output for sample input for details. You can assume that the output for the test cases will fit in64-bit signed integers.

Sample Input

2 2
2 3
3 3
0 0

Sample Output

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

解题思路请参考: http://www.cnblogs.com/xiaocai905767378/archive/2011/04/27/2030213.html

注意啊注意: 用long long

row_a = 20000

roe_b = 20000 时, 会超啊~

AC代码:

#include<stdio.h>

long long a, b;
int cas = 0; int main() {
while(scanf("%lld %lld", &a, &b) != EOF) {
if(a == 0 && b == 0)
break;
long long ans = (a * (a-1) * b * (b-1) / 4);
printf("Case %d: %lld\n", ++cas, ans);
}
return 0;
}

UVA 10790 (13.08.06)的更多相关文章

  1. UVA 253 (13.08.06)

     Cube painting  We have a machine for painting cubes. It is supplied withthree different colors: blu ...

  2. UVA 573 (13.08.06)

     The Snail  A snail is at the bottom of a 6-foot well and wants to climb to the top.The snail can cl ...

  3. UVA 10499 (13.08.06)

    Problem H The Land of Justice Input: standard input Output: standard output Time Limit: 4 seconds In ...

  4. UVA 10025 (13.08.06)

     The ? 1 ? 2 ? ... ? n = k problem  Theproblem Given the following formula, one can set operators '+ ...

  5. UVA 10194 (13.08.05)

    :W Problem A: Football (aka Soccer)  The Problem Football the most popular sport in the world (ameri ...

  6. UVA 465 (13.08.02)

     Overflow  Write a program that reads an expression consisting of twonon-negative integer and an ope ...

  7. UVA 10494 (13.08.02)

    点此连接到UVA10494 思路: 采取一种, 边取余边取整的方法, 让这题变的简单许多~ AC代码: #include<stdio.h> #include<string.h> ...

  8. UVA 424 (13.08.02)

     Integer Inquiry  One of the first users of BIT's new supercomputer was Chip Diller. Heextended his ...

  9. UVA 10106 (13.08.02)

     Product  The Problem The problem is to multiply two integers X, Y. (0<=X,Y<10250) The Input T ...

随机推荐

  1. Technology share: VR is coming,are you ready?

    ►Date 2016-10-18 ►Address 上海市浦东新区严家桥1号宏慧音悦湾3号楼5楼 VR SPACE ►Events 品牌如何抢先一步,借玩VR吸引眼球,如何让客户作为VR买单? 如何结 ...

  2. SSH 公私钥的基本使用

    SSH 公私钥的基本使用 创建密钥 使用 ssh-keygen 生成公私钥 在终端敲入 ssh-keygen 命令,一路一直按回车下去,会把密钥文件放置在默认路径,也就是 ~/.ssh/ 路径下,并且 ...

  3. JS 汉字与Unicode码的相互转化

    js文件中,有些变量的值可能会含有汉字,画面引入js以后,有可能会因为字符集的原因,把里面的汉字都变成乱码.后来发现网上的一些js里会把变量中的汉字都表示成”\u“开头的16进制编码,这样应该可以解决 ...

  4. viewpager切换耗时控制

    原文地址https://my.oschina.net/javalover/blog/179003 public class FixedSpeedScroller extends Scroller { ...

  5. enumerate()和map()函数用法

    一.python enumerate用法 先出一个题目: 1.有一 list= [1, 2, 3, 4, 5, 6] 请打印输出: 0, 1 1, 2 2, 3 3, 4 4, 5 5, 6 打印输出 ...

  6. 湖南大学ACM程序设计新生杯大赛(同步赛)B - Build

    题目描述 In country  A, some roads are to be built to connect the cities.However, due to limited funds, ...

  7. 洛谷P3639 [APIO2013] 道路费用 [生成树的特殊算法]

    题目传送门 道路费用 格式难调,题面就不放了. 分析: 这是一道要细(yan)心(jing)的生成树的好(gui)题. 首先我们看到$k$的范围非常小,那么我们就可以直接$2^k$枚举每一条加边是否选 ...

  8. 所以学树分块的时候为什么要看vector啊sjb

    明明应该拼命刷题却悠哉补着vector和指针 -------------------------------------------------------------------题记 http:// ...

  9. loj2576 「TJOI2018」str

    link 题意: 给一个模板串s和n个模式串,每个模式串有$a_i$种可取的串.现在要将n个模式串每个任取一种它可取的串,连接起来,记为串t,那么这种连接方式对答案的贡献为t在s中出现的次数.问所有连 ...

  10. 20162325 金立清 S2 W8 C17

    20162325 2017-2018-2 <程序设计与数据结构>第8周学习总结 教材学习内容概要 二叉查找树是一棵二叉树,对于其中的每个结点,左子树上的元素小于父结点的值,而右子树上的元素 ...