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. c语言中--typeof--关键字用法

    C语言中 typeof 关键字是用来定义变量数据类型的.在linux内核源代码中广泛使用. 下面是Linux内核源代码中一个关于typeof实例: #define min(x, y) ({ \ typ ...

  2. [BZOJ] 3875: [Ahoi2014&Jsoi2014]骑士游戏

    设\(f[x]\)为彻底杀死\(x\)号怪兽的代价 有转移方程 \[ f[x]=min\{k[x],s[x]+\sum f[v]\} \] 其中\(v\)是\(x\)通过普通攻击分裂出的小怪兽 这个东 ...

  3. 入门学习Linux常用必会命令实例详解

    Linux提供了大量的命令,利用它可以有效地完成大量的工作,如磁盘操作.文件存取.目录操作.进程管理.文件权限设定等.所以,在Linux系统上工作离不开使用系统提供的命令.要想真正理解Linux系统, ...

  4. ASP.NET Core模块化前后端分离快速开发框架介绍之2、快速创建一个业务模块

    源码地址 GitHub:https://github.com/iamoldli/NetModular 演示地址 地址:https://nm.iamoldli.com 账户:admin 密码:admin ...

  5. 小程序wafer2操作数据库

    小程序操作数据库 //小程序控制台phpmyadmin里给数据库cAuth添加表 //controllers/hello.js const { mysql } = require('../qcloud ...

  6. h5获取摄像头拍照功能

    完整代码展示 <!DOCTYPE html> <head> <title>HTML5 GetUserMedia Demo</title> <met ...

  7. Python知识点进阶——细节问题

    int()强制转换浮点数 在int()的强制转换浮点数时候,不管是正数还是负数,只取整数部分. 注意:这里不是向上或者向下取整,也不是四舍五入. 无限递归 递归是为了将问题简化为更小规模的同类型问题, ...

  8. 初学js之qq聊天实例

    实现的功能为上图所示,但是每新发送的消息必须显示在最上面. 我实现了两版,样式有是一样的.我们直接看代码. 版本一: <!DOCTYPE html> <html lang=" ...

  9. emwin如何在windows10下vs2015或2017进行仿真。

    Make sure the selected Windows SDK is installed:Properties -> Configuration Properties -> Gene ...

  10. HDU 6156 回文 数位DP(2017CCPC)

    Palindrome Function Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 256000/256000 K (Java/Ot ...