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<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>

#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<n;i++)
			for(j=2;j<m;j++)
		{
			ll temp=gcd(i,j)-1;
			temp=temp*(n-i)*(m-j)*2;
			ans-=temp;
 		}
       printf("%lld\n",ans);
	}
    return 0;
}






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值