程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> ZOJ 3647 Gao the Grid(居然是暴力)

ZOJ 3647 Gao the Grid(居然是暴力)

編輯:C++入門知識

ZOJ 3647 Gao the Grid(居然是暴力)


A n * m grid as follow:

a n*m grid(n=4,m=3)

Count the number of triangles, three of whose vertice must be grid-points.
Note that the three vertice of the triangle must not be in a line(the right picture is not a triangle).

a triangle not a triangle

Input

The input consists of several cases. Each case consists of two positive integers n and m (1 ≤ n, m ≤ 1000).

Output

For each case, output the total number of triangle.

Sample Input

1 1
2 2

Sample Output

4
76

hint

hint for 2nd case: C(9, 3) - 8 = 76


題目意思 : 給你矩形長度,求在裡面取3個點,問可以組成三角形的個數?


一共有(n+1)*(m+1)個點,去3個


然後減去同行取3個,同列取3個;


最後減去左斜和右斜的,這種情況居然是枚舉三角形的長高!!!!!


#include
#include
#include
#include
#include
#include
#include
#include

#define eps 1e-8
using namespace std;
#define N 10005

typedef long long ll;

ll L(ll x)
{
	return (ll)(x*(x-1)*(x-2)/6);
}

ll gcd(ll n,ll m)
{
	if(m==0)  return n;
	return gcd(m,n%m);
}

int main()
{
	ll i,j,n,m;
	while(~scanf("%lld%lld",&n,&m))
	{   n++;
	    m++;
		ll ans=L(n*m)-L(n)*m-L(m)*n;
		for(i=2;i





  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved