标签:
3 3 2 -1 0 0 1 1 0 3 2 -1 0 0 0 1 0 3 1 -1 0 0 1 1 0
3 1 -1
/************************************************************************* > File Name: hdu4305.cpp > Author: ALex > Mail: 405045132@qq.com > Created Time: 2015年01月26日 星期一 21时31分21秒 ************************************************************************/ #include <map> #include <set> #include <queue> #include <stack> #include <vector> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <algorithm> using namespace std; const int N = 330; const int mod = 10007; int mat[N][N]; struct node { int x, y; }point[N]; int extend_gcd (int a, int b, int &x, int &y) { if (!b) { x = 1; y = 0; return a; } int gcd = extend_gcd (b, a % b, x, y); int t = x; x = y; y = t - (a / b) * x; } int get_inverse (int num) { int x, y; extend_gcd (num, mod, x, y); return (x % mod + mod) % mod; } int Det (int n) // 求行列式的值,涉及到除法,所以要用逆元 { for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { mat[i][j] = (mat[i][j] % mod + mod) % mod; } } int res = 1; for (int i = 0; i < n; ++i) { for (int j = i; j < n; ++j) { if (mat[j][i]) { for (int k = i; k < n; ++k) { swap (mat[i][k], mat[j][k]); } if (i != j) { res = (-res + mod) % mod; } break; } } if (!mat[i][i]) { res = -1; break; } for (int j = i + 1; j < n; ++j) { int mut = (mat[j][i] * get_inverse (mat[i][i])) % mod; for (int k = i; k < n; ++k) { mat[j][k] = (mat[j][k] - (mat[i][k] * mut) % mod + mod) % mod; } } res = (res * mat[i][i]) % mod; } return res; } bool is_line (int i, int j, int k) { int x1 = point[k].x - point[i].x; int y1 = point[k].y - point[i].y; int x2 = point[k].x - point[j].x; int y2 = point[k].y - point[j].y; return x1 * y2 - x2 * y1; } bool is_ok (int i, int j, int R, int n) { int x = point[i].x - point[j].x; int y = point[i].y - point[j].y; if (x * x + y * y > R * R) { return false; } for (int k = 0; k < n; ++k) { if (k == i || k == j) { continue; } if (point[k].x ) if (is_line(i, j, k)) { continue; } if ((point[k].x - point[i].x) * (point[k].x - point[j].x) > 0) { continue; } if ((point[k].y - point[i].y) * (point[k].y - point[j].y) > 0) { continue; } return false; } return true; } int main () { int t; scanf("%d", &t); while (t--) { int n, R; scanf("%d%d", &n, &R); for (int i = 0; i < n; ++i) { scanf("%d%d", &point[i].x, &point[i].y); } memset (mat, 0, sizeof(mat)); for (int i = 0; i < n; ++i) { for (int j = i + 1; j < n; ++j) { if (is_ok (i, j, R, n)) { mat[i][j] = -1; mat[j][i] = -1; } } } for (int i = 0; i < n; ++i) { int tmp = 0; for (int j = 0; j < n; ++j) { tmp += mat[i][j]; } mat[i][i] = -tmp; } int ans = Det (n - 1); printf("%d\n", ans); } return 0; }
标签:
原文地址:http://blog.csdn.net/guard_mine/article/details/43164671