hdu4305---Lightning

Lightning

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 1565    Accepted Submission(s): 515

Problem Description

There are N robots standing on the ground (Don‘t know why. Don‘t know how).

Suddenly the sky turns into gray, and lightning storm comes! Unfortunately, one of the robots is stuck by the lightning!

So it becomes overladen. Once a robot becomes overladen, it will spread lightning to the near one.

The spreading happens when:

Robot A is overladen but robot B not.

The Distance between robot A and robot B is no longer than R.

No other robots stand in a line between them.

In this condition, robot B becomes overladen.

We assume that no two spreading happens at a same time and no two robots stand at a same position.

The problem is: How many kind of lightning shape if all robots is overladen? The answer can be very large so we output the answer modulo 10007. If some of the robots cannot be overladen, just output -1.

Input

There are several cases.

The first line is an integer T (T < = 20), indicate the test cases.

For each case, the first line contains integer N ( 1 < = N < = 300 ) and R ( 0 < = R < = 20000 ), indicate there stand N robots; following N lines, each contains two integers ( x, y ) ( -10000 < = x, y < = 10000 ), indicate the position of the robot.

Output

One line for each case contains the answer.

Sample Input

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

Sample Output

3
1
-1

Author

BUPT

Source

2012 Multi-University Training Contest 1

Recommend

生成树计数, martix-tree定理,行列式那边取模时要用逆元

/*************************************************************************
    > File Name: hdu4305.cpp
    > Author: ALex
    > Mail: [email protected]
    > 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;
}
时间: 2024-11-15 19:05:58

hdu4305---Lightning的相关文章

HDU4305:Lightning(生成树计数+判断点是否在线段上)

Lightning Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2465    Accepted Submission(s): 912 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4305 Description: There are N robots standing on the

【HDU 4305】Lightning(生成树计数)

Problem Description There are N robots standing on the ground (Don't know why. Don't know how). Suddenly the sky turns into gray, and lightning storm comes! Unfortunately, one of the robots is stuck by the lightning!So it becomes overladen. Once a ro

【HDOJ】4305 Lightning

1. 题目描述当一个结点lightning后,可以向其周围距离小于等于R的结点传播lightning.然后以该结点为中心继续传播.以此类推,问最终形成的树形结构有多少个. 2. 基本思路生成树级数模板题目.Matrix-Tree定理(Kirchhoff矩阵-树定理):1) G的度数矩阵D[G]是一个n*n的矩阵,并且满足:当i≠j时,dij=0:当i=j时,dij等于vi的度数:2) G的邻接矩阵A[G]也是一个n*n的矩阵, 并且满足:如果vi.vj之间有边直接相连,则aij=1,否则为0.定

[Immutable.js] Lightning Fast Immutable.js Equality Checks with Hash Codes

While Immutable.js offers .is() to confirm value equality between iterables it comes at the cost of referencing each key and value in both objects. For lightning fast equality checks, Immutable.js can produce a hash code based on an iterable's conten

【BZOJ2216】[Poi2011]Lightning Conductor 决策单调性

[BZOJ2216][Poi2011]Lightning Conductor Description 已知一个长度为n的序列a1,a2,...,an.对于每个1<=i<=n,找到最小的非负整数p满足 对于任意的j, aj < = ai + p - sqrt(abs(i-j)) Input 第一行n,(1<=n<=500000)下面每行一个整数,其中第i行是ai.(0<=ai<=1000000000) Output n行,第i行表示对于i,得到的p Sample I

Lightning线缆如何分真假 苹果官网告诉你

今天早些时候苹果更新了支持页面,希望能够帮助顾客识别仿制或者是未经授权的 Lightning 配件.如果顾客使用了非 MFi 认证的 Lightning 线缆的话,他们很可能会遇到下面的问题: iOS 设备可能会损坏 线缆容易损坏 线缆接口或许会受损,并发热,或者是不适合你的设备 无法同步或为你的设备充电 苹果表示正版的线缆会印有“Designed by Apple in California” 和“Assembled in China,”或者是 “Assembed in Vietnam,”和“

HDU 4305 Lightning Matrix Tree定理

题目链接:https://vjudge.net/problem/HDU-4305 解法:首先是根据两点的距离不大于R,而且中间没有点建立一个图.之后就是求生成树计数了. Matrix-Tree定理(Kirchhoff矩阵-树定理).Matrix-Tree定理是解决生成树计数问题最有力的武器之一.它首先于1847年被Kirchhoff证明.在介绍定理之前,我们首先明确几个概念: 1.G的度数矩阵D[G]是一个n*n的矩阵,并且满足:当i≠j时,dij=0:当i=j时,dij等于vi的度数. 2.G

HDOJ 4305 Lightning 生成树计数

Lightning Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1588    Accepted Submission(s): 525 Problem Description There are N robots standing on the ground (Don't know why. Don't know how). Sud

Lightning框架示例 - 动态建立Lightning组件

动态建立Lightning组件 组件化前端开发是Lightning框架的优点之一.在进行Lightning应用开发时,我们可以将组件进行嵌套.引用,从而实现模块的封装和重用,提高开发效率. 组件的嵌套和引用最常用的方法是在Lightning组件中直接使用组件标签,比如: <aura:component controller="ExampleController"> <c:ExampleChildComponent /> </aura:component&g

053_Salesforce Lightning与Classic对比

Classic页面  Lightning页面  特点: 应用程序的切换更加方便 可以快速访问最近项目和备注等 新的记录页面布局 涡轮增压列表视图 仪表板有所变化 圆滑的报告视图 其中最重要的变化也当属页面布局,整个页面更加友好,且适应移动端,也符合未来趋势 editions 支持的editions 不支持的editions Group Edition(GE) Personal Edition Professional Edition(PE) Contact Manager Edition Ent