uva 10790 How Many Points of Intersection?
来源:互联网 发布:淘宝旺铺智能版功能 编辑:程序博客网 时间:2024/06/05 19:10
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 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 < a ≤ 20000) and b (0 < b ≤ 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(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-bit signed integers.
Sample Input
2 2
2 3
3 3
0 0
Universidad de Valladolid OJ: 10790 – How Many Points of Intersection? 2/2
Sample Output
Case 1: 1
Case 2: 3
Case 3: 9
/*Author:ZCC;Solve:假设f(a,b)表示它们有多少交点。 结论:f(a,b)=a(a-1)b(b-1)/4 可以利用数学归纳法证明。 首先,a=1时,f(1,b) = 0 . a=2 时,计算f(2,b),如图所示,L1有两点,P1,P2;L2上有A1、A2、A3、……Ab 共b个点,先连接P1A1、P1A2、P1A3、……、P1Ab。另一点P2再与A1连接没有交点,与A2有1个交点,与A3连接有2个交点,……,与Ab有b-1个交点。 由加法原理得出:f(2,b)=0+1+2+……+b-1=b(b-1)/2 设a=k时,上式成立,即f(k,b) = b(b-1)/2 *a(a-1)/2=a(a-1)b(b-1)/4 对于a=k+1,第k+1个点与b个点连接,得到点为: 0+k+2k+…+(b-1)k=k(0+1+2+...+(b-1) )=kb(b-1)/2 则: f(k+1,b)=kb(b-1)/2+b(b-1)k(k-1)/4=b(b-1)k(k+1)/4 即当n=k+1时,结论成立。*/using namespace std;#include<iostream>#include<algorithm>#include<map>#include<cstdio>#include<cstdlib>#include<vector>#include<cmath>#include<cstring>#include<string>const int maxn=55;typedef long long LL;int main(){ #ifndef ONLINE_JUDGE ///freopen("Text//in.txt","r",stdin); #endif // ONLINE_JUDGE LL n,m; int cas=1; while(scanf("%lld%lld",&n,&m)&&(n||m)){ printf("Case %d: %lld\n",cas++,n*(n-1)/2*m*(m-1)/2); } 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?
- 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?
- 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?
- UVA - 10790 How Many Points of Intersection?
- UVA - 10790 How Many Points of Intersection?
- uva 10790 How Many Points of Intersection?
- OpenCV之十三 OpenCV图像金字塔:高斯金字塔、拉普拉斯金字塔与图片尺寸缩放
- 易經大意原稿(頁單位) 301-325
- 成本中心主数据屏幕增强
- 实战Memcached缓存系统(1)Memcached基础及示例程序
- 学生成绩管理系统
- uva 10790 How Many Points of Intersection?
- OpenCV在Visual Studio开发环境的搭建
- OpenCV之十四 OpenCV霍夫变换:霍夫线变换,霍夫圆变换合辑
- uva11044 Searching for Nessy
- 易經大意原稿(頁單位) 276-300
- leetcode - Decode Ways
- Linux系统下如何查看及修改文件读写权限
- OpenCV之十五 水漫金山:OpenCV漫水填充算法(Floodfill)
- 探索 ConcurrentHashMap 高并发性的实现机制