uva 10790 How Many Points of Intersection?

题意:有两个线,一在上,一在下,两线上各有n,m个点,使它们两两相连,使达到的交点最多(不包括线上的点),问你交点的数目。

把第一个坐标排序后,求第二个坐标的逆序对个数。

#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
    int n,m,t_cnt=0;
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        if(n==0&&m==0) break;
        long long k=(m)*(m-1)/2;
        long long ans=k*(n)*(n-1)/2;
        printf("Case %d: %lld\n",++t_cnt,ans);
    }
    return 0;
}


你可能感兴趣的:(uva 10790 How Many Points of Intersection?)