10790 - How Many Points of Intersection?
来源:互联网 发布:c gui qt4编程 编辑:程序博客网 时间:2024/06/06 02:52
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(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
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(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-bitsigned integers.
Sample Input
2 22 33 30 0
Sample Output
Case 1: 1Case 2: 3Case 3: 9
这道题没什么好说的,有个公式:a*(a-1) * b * (b -1)/4
要注意数据的范围。int型在运算的过程如果超过了int型,不能直接赋值给long long。
#include<iostream>#include<cstdio>#include<cmath>#include<cstring>#include<string>#include<ctype.h>#include<algorithm>#include<queue>#include<stack>using namespace std;int main (){ long long a,b; int p=1; long long t; while(cin>>a>>b) { if (a==0) break; t=a*(a-1)*b*(b-1)/4; printf("Case %d: %lld\n",p,t); p++; } return 0;}
- UVa 10790 How Many Points of Intersection?
- uva 10790 How Many Points of Intersection?
- uva 10790 - How Many Points of Intersection?
- uva-10790-How Many Points of Intersection?
- UVa 10790 - How Many Points of Intersection?
- 10790 - How Many Points of Intersection?
- Uva 10790 - How Many Points of Intersection?
- 10790 - How Many Points of Intersection?
- UVa 10790 - How Many Points of Intersection?
- 10790 - How Many Points of Intersection?
- UVA 10790 How Many Points of Intersection?
- uva 10790 - How Many Points of Intersection
- uva 10790 How Many Points of Intersection?
- UVa 10790 How Many Points of Intersection?
- 10790 - How Many Points of Intersection?
- uva - 10790 - How Many Points of Intersection?
- UVa 10790 - How Many Points of Intersection?
- UVa 10790 - How Many Points of Intersection?
- exp 导多个用户数据时报 syntax error near unexpected token `('
- 使用SQL语句操作SQLite数据库
- 经典SQL语句大全
- UVA 10106 - Product(大数乘法)
- 21个值得收藏的Javascript技巧
- 10790 - How Many Points of Intersection?
- Android应用开发——退出确认对话框 后退键捕捉
- struts漏洞修补过程之S2-016
- c++中的虚函数
- QT 学习笔记 一Qt SDK 的下载安装与配置
- Word,Excel,Powerpoint,Txt,Pdf 等文档的在线浏览的实现
- (Problem 4)Largest palindrome product
- Android软件中嵌入地图之一:Sogou地图
- STL中的所有算法,STL概述,STL,STL通用算法,STL入门学习