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. Ansible指令和常用模块使用

    这里文章记录一下ansible的指令选项和常用的模块使用 ansible指令选项 -m:要执行的模块,默认为command -a:模块的参数 -u:ssh连接的用户名,默认用root,ansible. ...

  2. 配置vim nginx.conf高亮

    #!/bin/bashwget http://www.vim.org/scripts/download_script.php?src_id=14376 -O nginx.vimmv nginx.vim ...

  3. tcl之变量-简单变量

  4. win7旗舰版64位java的jdk环境变量的配置(2012-12-26-bd 写的日志迁移

    首先到oracle的官方网站http://www.oracle.com/technetwork/cn/java/javase/downloads/index.html下个JDK比如下图: 必须是win ...

  5. 3分钟快速了解FastDFS

    1.介绍 FastDFS是一个C语言写的阿里开源的分布式文件存储服务器主要由两部分组成:1.Tracker server ——————主要负责调度和追踪Storage状态(调度服务器),默认监听端口: ...

  6. Python9-MySQL-MySQL-ORM框架-day48

    ORM框架:AQLAlchemy-作用: 1.提供简单的规则 2.自动转换成SQL语句 -DB first: 手动创建数据库以及表 -> ORM框架 -> 自动生成类 code first ...

  7. 使用HTTP协议访问网络

    在Android上发送http请求有2种方式,分别由两个类完成,HttpURLConnection和HttpClient. 一.使用HttpURLConnection方式 1.1 建立连接的基本步骤 ...

  8. A1009 Product of Polynomials (25)(25 分)

    A1009 Product of Polynomials (25)(25 分) This time, you are supposed to find A*B where A and B are tw ...

  9. synchronized 基本用法

    常见三种使用方式 1)普通同步方法,锁是当前实例:2)静态同步方法,锁是当前类的Class实例,Class数据存在永久代中,是该类的一个全局锁:3)对于同步代码块,锁是synchronized括号里配 ...

  10. Android学习笔记之-----讯飞语音识别实例化RecognizerDialog参数出现错误的解决方法

    本人也是个小菜鸟,在做语音识别时也遇到了这个问题,空指针一直报错,app程序停止运行. 在网上搜了半天在这个帖子里找到了解决方法:http://bbs.xfyun.cn/forum.php?mo .. ...