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. 

InputThere 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.
OutputOne 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

题目配图戳中笑点2333

大意:给出n个点,求生成树数量,两个点之间有无向边需要满足:两点距离小于给定的R,且两点所连线段上没有其他点

图论 矩阵树定理 模方程

n只有300,于是直接O(n^3)暴力判断两点间是否有边(判距离+判斜率)

建出Matrix-Tree定理的矩阵后,高斯消元计算矩阵行列式的值,输出答案,无解输出-1

注意到矩阵是处在模意义下的,又去学了一下高斯消元解线性模方程组

↑全程循环着シカコ的《胃が痛いんだなぁ》,灵感泉涌,一次AC,带感

  ↑这歌真的很棒呢(跑题)

 /*by SilverN*/
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
const int mod=;
const double eps=1e-;
const int mxn=;
int read(){
int x=,f=;char ch=getchar();
while(ch<'' || ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>='' && ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
struct block{
int x,y;
}a[mxn];
int n,R;
int D;
int G[mxn][mxn];
bool vis[mxn];
void exgcd(int a,int b,int &x,int &y){//求逆元用
if(!b){x=;y=;return;}
exgcd(b,a%b,x,y);
int t=x;x=y;y=t-a/b*x;
return;
}
int Gauss(){//Matrix-tree定理 高斯消元
int i,j,x,y;
int ans=;
for(i=;i<n;i++){
int p=i;
if(!G[i][i]){
for(j=i+;j<n;j++)if(G[j][i]>G[p][i])p=j;
if(p==i){return -;}//无解
for(j=;j<n;j++)swap(G[p][j],G[i][j]);
ans=-ans;
}
exgcd(G[i][i],mod,x,y);
x=((x%mod)+mod)%mod;
for(int k=i+;k<n;k++)(G[i][k]*=x)%=mod;
for(j=i+;j<n;j++){
if(G[j][i]){
for(int k=i+;k<n;k++){
G[j][k]=((G[j][k]-G[i][k]*G[j][i])%mod+mod)%mod;
}
}
}
ans=ans*G[i][i]%mod;
}
return ans;
}
inline int dist(int i,int j){//距离
return (a[i].x-a[j].x)*(a[i].x-a[j].x)+(a[i].y-a[j].y)*(a[i].y-a[j].y);
}
inline double ck(int i,int j){//斜率
return ((double)a[i].y-a[j].y)/(double)(a[i].x-a[j].x);
}
bool check(int x,int y){
int dis=dist(x,y);
if(dis>D)return ;//距离大于R
double k=ck(x,y);
for(int i=;i<=n;i++){
if(i==y || i==x)continue;
if(dist(x,i)<dis && fabs(ck(x,i)-k)<eps)return ;//连线上有其他机器人
}
return ;
}
void solve(){
int i,j,k;
for(i=;i<=n;i++)
for(j=i+;j<=n;j++){
if(check(i,j)){
++G[i][i]; ++G[j][j];
--G[i][j]; --G[j][i];
vis[i]=vis[j]=;
}
}
for(i=;i<=n;i++)
if(!vis[i]){printf("-1\n");return;}
for(i=;i<=n;i++)
for(j=;j<=n;j++){
G[i][j]=((G[i][j]%mod)+mod)%mod;
}
printf("%d\n",Gauss());
return;
}
void init(){
memset(G,,sizeof G);
memset(vis,,sizeof vis);
return;
}
int main(){
int i,j;
int T=read();
while(T--){
init();
n=read();R=read();D=R*R;
for(i=;i<=n;i++){a[i].x=read();a[i].y=read();}
solve();
}
return ;
}

HDU4305 Lightning的更多相关文章

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

    Lightning Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

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

    Problem Description There are N robots standing on the ground (Don't know why. Don't know how). Sudd ...

  3. 【HDOJ】4305 Lightning

    1. 题目描述当一个结点lightning后,可以向其周围距离小于等于R的结点传播lightning.然后以该结点为中心继续传播.以此类推,问最终形成的树形结构有多少个. 2. 基本思路生成树级数模板 ...

  4. [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 ...

  5. Redisql: the lightning fast data polyglot【翻译】 - Linvo's blog - 博客频道 - CSDN.NET

    Redisql: the lightning fast data polyglot[翻译] - Linvo's blog - 博客频道 - CSDN.NET Redisql: the lightnin ...

  6. 张高兴的 Windows 10 IoT 开发笔记:使用 Lightning 中的软件 PWM 驱动 RGB LED

    感觉又帮 Windows 10 IoT 开荒了,所以呢,正儿八经的写篇博客吧.其实大概半年前就想写的,那时候想做个基于 Windows 10 IoT 的小车,但树莓派原生不支持 PWM 啊.百度也搜不 ...

  7. salesforce lightning零基础学习(一) lightning简单介绍以及org开启lightning

    lightning对于开发salesforce人员来说并不陌生,即使没有做过lightning开发,这个名字肯定也是耳熟能详.原来的博客基本都是基于classic基于配置以及开发,后期博客会以ligh ...

  8. salesforce lightning零基础学习(二) lightning 知识简单介绍----lightning事件驱动模型

    看此篇博客前或者后,看一下trailhead可以加深印象以及理解的更好:https://trailhead.salesforce.com/modules/lex_dev_lc_basics 做过cla ...

  9. salesforce lightning零基础学习(三) 表达式的!(绑定表达式)与 #(非绑定表达式)

    在salesforce的classic中,我们使用{!expresion}在前台页面展示信息,在lightning中,上一篇我们也提及了,如果展示attribute的值,可以使用{!v.expresi ...

随机推荐

  1. GNU C中__attribute__

    __attribute__基本介绍: 1. __attribute__ 可以设置函数属性.变量属性和类型属性. 2. __attribute__ 语法格式为:__attribute__ ((attri ...

  2. MySQL - GROUP_CONCAT 使用方法

    如上图,我想把结果集中的三行链接成一行,则可这样写:   总结: GROUP_CONCAT函数默认是用','逗号链接,如果你加上第二个参数,则以',第二个参数值'逗号+第二个参数值链接,如下图     ...

  3. Centos 安装python 3.7 ,同时兼容python2.7

    下载Python源码 从http://www.python.org/download/根据需要的版本下载源文件. 例如上图就是我在官网直接找到3.5.6版本的下载页面,点击的tar源码包进行下载. 1 ...

  4. Linux系统故障分析与排查--日志分析

    处理Linux系统出现的各种故障时,故障的症状是最先发现的,而导致这以故障的原因才是最终排除故障的关键.熟悉Linux系统的日志管理,了解常见故障的分析与解决办法,将有助于管理员快速定位故障点,“对症 ...

  5. SSH密钥验证

    基于密钥验证 1. 在客户端生成密钥对 可以先进入用户的.ssh 目录 cd ~/.ssh ssh-keygen -t rsa [-P '' ] [-f "~/.ssh/id_rsa&quo ...

  6. yii2 基本的增删改查

    一:添加方法 1.1 使用成员属性的方式 save $user_name = $_POST['user_name']; $password = $_POST['password']; //实例化 $u ...

  7. MTCNN学习进展

    20190618 截止今日,学习了MTCNN预测部分的内容,包括三个网络输入输出之类的东西. 之后需要进一步学习的,NMS原理鞋机,MTCNN训练过程细节,损失函数细节

  8. 动态规划、记忆化搜索:HDU1978-How many ways

    Problem Description 这是一个简单的生存游戏,你控制一个机器人从一个棋盘的起始点(1,1)走到棋盘的终点(n,m).游戏的规则描述如下: 1.机器人一开始在棋盘的起始点并有起始点所标 ...

  9. 使用 Region,RegionManager 在 XNA 中创建特殊区域(十八)

    平方已经开发了一些 Windows Phone 上的一些游戏,算不上什么技术大牛.在这里分享一下经验,仅为了和各位朋友交流经验.平方会逐步将自己编写的类上传到托管项目中,没有什么好名字,就叫 WPXN ...

  10. 微信小程序-----校园头条详细开发之列表展示数据

    1.分类列表数据展示功能的实现 1.1 结构 1.2 代码实现 1.2.1  列表显示数据,.每次界面显示6条数据,发请求获取数据,动态存放 var app = getApp() Page({ dat ...