您的位置:首页 > 其它

UVA 10790 How Many Points of Intersection?

2016-07-15 19:45 337 查看

UVA-10790

题意:给出n,m,表示上面一条线有n个点,下面有m个点,上下的点相互连接,求交点的数量。

解题思路:先把上面的点摆好,下面第一个个点进去有 0 个交点,第二个点进去有 n-1 + n-2 + n-3 ……+1个交点,第三个点进去有 2*( n-1 + n-2 + n-3 + ……+ 1) ,到第m个进去有 (m-1)*(1+2+……+n-1) 。和为(1+2+3+……+n-1)*(1+2+3+……+m-1) 。套等差数列球和。

/*************************************************************************
> File Name: UVA-10790.cpp
> Author: Narsh
>
> Created Time: 2016年07月15日 星期五 09时13分16秒
************************************************************************/

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
int main () {
long long n,m,num=0;
while (cin>>n>>m && n+m) {
printf("Case %lld: ",++num);
cout<<n*(n-1)*m*(m-1)/4LL<<endl;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: