# UVA 10790

Thinking : It's a quite easy problem if you can find the relationship between P(a,b) and P(a-1,b) or P(a,b-1).
Based on our math knowledge  and observation from the picture, we can know that P(a,b) = P(a-1,b) + (a-1)*(b*(b-1)/2).

AC code:

#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#define MIN(a,b) ((a)<(b)?(a):(b))
#define epsilon 1.0e-6
#define lli long long int
using namespace std;
//lli P[20005][20005];
lli parent(lli a,lli b)
{
if (a == 1 || b == 1)
return 0;
return parent(a - 1, b) + (a - 1)*(b*(b - 1)) / 2;
}

int main()
{
lli a, b;
int T = 0;

while (1)
{
T++;
scanf("%lld%lld", &a, &b);
if (a == 0 && b == 0)
break;
lli ans = parent(a, b);
printf("Case %d: %lld\n", T, ans);
}

return 0;

}

• 本文已收录于以下专栏：

## UVA - 10790 How Many Points of Intersection?

We have two rows. There are a dots on the toprow and b dots on the bottom row. We draw line segment...

## UVA10790 How Many Points of Intersection?

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

## 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 ...

## uva10790

/* 虽然这道题不是很难，还是wa了一次，以前没用过longlong型的数据啊！！但这题还是令人长自信，因为我的推理过程没用到任何高深的数学公式、定理等等 题目大意 给定2条平行的直...

## uva 10790 How Many Points of Intersection?

10790 How Many Points of Intersection? We have two rows. There are a dots on the top row and b dots...

## uva 10790 How Many Points of Intersection?

uva 10790 How Many Points of Intersection? 题目大意;告诉你两条线上的定点个数，将点与电间连线，求交点个数。 解题思路：不解释。有规律 #includ...

## 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...

## 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 ...
• SIOFive
• 2013年07月24日 11:39
• 616

## 算法竞赛入门经典（第二版）3-12章习题+例题 UVa原题

• 2014年07月23日 18:27
• 19.98MB
• 下载

举报原因： 您举报文章：UVA 10790 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)