首页 > 代码库 > How Many Points of Intersection?

How Many Points of Intersection?

uva10790:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1731

题意:两条水平线,分别有n,m个点,点之间两两连线,求有多少个交点。

题解:手动模拟一下,然后用不完全归纳法,就可以得到公式ans=(n-1)*n/2*(m-1)*m/2;

 1 #include<iostream> 2 #include<cstdio> 3 #include<algorithm> 4 #include<cstring> 5 using namespace std; 6 long long m, n; 7 int main(){ 8     int tt=1; 9      while(~scanf("%lld%lld",&n,&m)){10         if(n==0&&m==0)break;11        printf("Case %d: %lld\n",tt++,(n-1)*n/2*(m-1)*(m)/2);12      }13 }
View Code