HDU4305 Lightning
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的更多相关文章
- HDU4305:Lightning(生成树计数+判断点是否在线段上)
Lightning Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- 【HDU 4305】Lightning(生成树计数)
Problem Description There are N robots standing on the ground (Don't know why. Don't know how). Sudd ...
- 【HDOJ】4305 Lightning
1. 题目描述当一个结点lightning后,可以向其周围距离小于等于R的结点传播lightning.然后以该结点为中心继续传播.以此类推,问最终形成的树形结构有多少个. 2. 基本思路生成树级数模板 ...
- [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 ...
- 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 ...
- 张高兴的 Windows 10 IoT 开发笔记:使用 Lightning 中的软件 PWM 驱动 RGB LED
感觉又帮 Windows 10 IoT 开荒了,所以呢,正儿八经的写篇博客吧.其实大概半年前就想写的,那时候想做个基于 Windows 10 IoT 的小车,但树莓派原生不支持 PWM 啊.百度也搜不 ...
- salesforce lightning零基础学习(一) lightning简单介绍以及org开启lightning
lightning对于开发salesforce人员来说并不陌生,即使没有做过lightning开发,这个名字肯定也是耳熟能详.原来的博客基本都是基于classic基于配置以及开发,后期博客会以ligh ...
- salesforce lightning零基础学习(二) lightning 知识简单介绍----lightning事件驱动模型
看此篇博客前或者后,看一下trailhead可以加深印象以及理解的更好:https://trailhead.salesforce.com/modules/lex_dev_lc_basics 做过cla ...
- salesforce lightning零基础学习(三) 表达式的!(绑定表达式)与 #(非绑定表达式)
在salesforce的classic中,我们使用{!expresion}在前台页面展示信息,在lightning中,上一篇我们也提及了,如果展示attribute的值,可以使用{!v.expresi ...
随机推荐
- gravity 使用操作。
gravity 使用操作.最近我司有一个比较奇葩的需求,我们的环境是主从,因为数据量较大会定期的删除数据,最近不行了,要求新建出来一个库 同步正事环境的数据,但是要剔除 delete ,drop,tr ...
- mysql 基础,列类型
- pycahrm git配置笔记
1. 在file - setting - plugins 中查看是否有github插件, 此处是用于处理插件位置
- 微信在浏览器打开前的提示页面Android与IOS判断
直接在网上扒一个页面,分分钟搞定! 先看一下效果 这是用微信开发工具打开的样式,直接上完整代码 <!DOCTYPE html> <html lang="en"& ...
- pandas库Series类型与基本操作
pandas读取excel的类型是dataFrame,然后提取每一列是一个Series类型 Series类型包括index和values两部分 a = pd.Series({'a':1,'b':5}) ...
- Linux常见的系統进程
前言 在日常运维工作中,经常会看到一些奇怪的系统进程占用资源比较高.而且总是会听到业务线同学询问“xxx这个是啥进程啊?咋开启了这么多?” 而这些系统级的内核进程都是会用中括号括起来的,它们会执行一些 ...
- 问题 B: 分组统计
分组统计 问题 B: 分组统计时间限制: 1 Sec 内存限制: 32 MB 提交: 416 解决: 107 [提交][状态][讨论版][命题人:外部导入] 题目描述 先输入一组数,然后输入其分组,按 ...
- 最近使用Nginx的一点新得
1.基本的负载配置 Nginx最简单的配置模块如下 upstream name{ server ip:port; server ip:port; } server { listen 80; serve ...
- Linux下 导入导出数据库
1.怎么找到mysql下的bin? 1.1首先我在网上百度了一些Linux下如何导入导出数据.基本都是用mysqldump命令,但是如果没有到指定目录 下,执行这个命令是没有用的.一开始我还以为要在m ...
- Python虚拟机类机制之instance对象(六)
instance对象中的__dict__ 在Python虚拟机类机制之从class对象到instance对象(五)这一章中最后的属性访问算法中,我们看到“a.__dict__”这样的形式. # 首先寻 ...