ACDream 1024:Triangles

Triangles

Time Limit: 2000/1000MS (Java/Others)  Memory Limit: 128000/64000KB (Java/Others)
Problem Description

How many triple of points  A(xA,yA),B(xB,yB),C(xC,yC) A(xA,yA),B(xB,yB),C(xC,yC) which:

  • xA,yA,xB,yB,xC,yCZ xA,yA,xB,yB,xC,yC∈Z

  • 0xA,xB,xC<n,0yA,yB,yC<m 0≤xA,xB,xC<n,0≤yA,yB,yC<m

  • SABCZ S△ABC∉Z? ( S S△ denotes the area of triangle)

Input

Two integers  n n and  m m.

( 1n,m109 1≤n,m≤109)

Output

The only integer denotes the number possible triples, modulo  109+7 109+7.

Sample Input
2 2
Sample Output
24
Hint

There are  4 4 triangles. Each of them is counted  6 6 times.

假设三角形的3的顶点分别为P1(x1,y1),P2(x2,y2),P3(x3,y3)
则向量a 就可以表示为(x2-x1,y2-y1)
向量b 就可以表示为(x3-x1,y3-y1)
根据二维向量叉积的运算 
∣a×b|=(x2-x1)(y3-y1) - (y2-y1)(x3-x1)
则这个三角形的面积
 S = |((x2 - x1) * (y3 - y1) - (y2 - y1) * (x3 - x1) ) / 2|

所以,算出每一个点四种情况的个数,然后深搜各个点的各种情况。

代码:

#pragma warning(disable:4996)
#include <iostream>
#include <functional>
#include <algorithm>
#include <cstring>
#include <vector>
#include <string>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <ctime>;
#include <set>
#include <map>
using namespace std;
typedef long long ll;

#define INF 0x3fffffffffffffff

const ll mod = 1e9 + 7;
const int maxn = 1e4 + 5;

ll n, m, res;
ll c[2][2];//c[0][0]代表都是偶数的情况数

void dfs(int num, int x1, int y1, int x2, int y2, int x3, int y3)
{
	if (num == 4)
	{
		if (((x2 - x1) * (y3 - y1) - (y2 - y1) * (x3 - x1)) % 2 != 0)
		{
			res += (((c[x1 % 2][y1 % 2] * c[x2 % 2][y2 % 2])%mod * c[x3 % 2][y3 % 2]))%mod;
			res %= mod;
		}
	}
	else
	{
		int i, j;
		for (i = 1; i <= 2; i++)
		{
			for (j = 1; j <= 2; j++)
			{
				if (num == 1)
				{
					dfs(num + 1, i, j, 3, 3, 3, 3);
				}
				else if (num == 2)
				{
					dfs(num + 1, x1, y1, i, j, 3, 3);
				}
				else if (num == 3)
				{
					dfs(num + 1, x1, y1, x2, y2, i, j);
				}
			}
		}
	}
}

void solve()
{
	ll i, j, k, x, y;
	scanf("%lld%lld", &n, &m);
	for (i = 0; i < 2; i++)
	{
		for (j = 0; j < 2; j++)
		{
			if (i == 0)
				x = (n - 1) / 2 + 1;
			else
				x = n / 2 ;
			if (j == 0)
				y = (m - 1) / 2 + 1;
			else
				y = m / 2;
			c[i][j] = (x*y) % mod;
		}
	}

	res = 0;
	dfs(1, 3, 3, 3, 3, 3, 3);
	printf("%lld\n", res);
}

int main()
{
//#ifndef ONLINE_JUDGE
//	freopen("i.txt", "r", stdin);
//	freopen("o.txt", "w", stdout);
//#endif

	solve();

	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值