ACDream 1024:Triangles

来源:互联网 发布:怎么用u盘安装ubuntu 编辑:程序博客网 时间:2024/05/22 19:26

Triangles

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

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,yCZxA,yA,xB,yB,xC,yC∈Z

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

  • SABCZS△ABC∉Z? (SS△ denotes the area of triangle)

Input

Two integers nn and mm.

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

Output

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

Sample Input

2 2

Sample Output

24

Hint

There are 44 triangles. Each of them is counted 66 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 0x3fffffffffffffffconst 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;elsex = n / 2 ;if (j == 0)y = (m - 1) / 2 + 1;elsey = 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);//#endifsolve();return 0;}


0 0
原创粉丝点击