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 ...
随机推荐
- 微信小程序的开发——01小程序的执行流程是怎样的?
作者:叶小钗 转载至:https://www.cnblogs.com/yexiaochai/p/9346043.html 我们这边最近一直在做基础服务,这一切都是为了完善技术体系,这里对于前端来说便是 ...
- zabbix监控系统时间的问题
分类: 监控 2013-03-19 21:40:11 发现zabbix监控系统时间的一个问题!zabbix监控系统时间用的key是system.localtime,返回当前的系统时间,而配置tig ...
- Steamroller-freecodecamp算法题目
Steamroller 1.要求 对嵌套的数组进行扁平化处理.你必须考虑到不同层级的嵌套. 2.思路 设定结果数组res 用for循环遍历arr的元素,判断是否为数组,是,则用res=res.conc ...
- Duizi and Shunzi HDU - 6188 (贪心)2017 广西ACM/ICPC
Duizi and Shunzi Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- 【css】cursor鼠标指针光标样式知识整理
在前端开发中,我们经常需要对对象鼠标指针光标进行控制,比如鼠标经过超链接时变成手指形状.在这里整理一下cursor鼠标指针光标样式的知识,记录与方便以后查找. 1.常用cursor光标 div( cu ...
- vmware 开机自动启动
vmware开机自动启动, 可以使用vmrun命令. 1. 首先在“我的电脑”-“属性”-“高级”-“环境变量”-“PATH”中添加vmware路径,如:C:\Program Files (x86)\ ...
- python正则表达式入门篇
文章来源于:https://www.cnblogs.com/chuxiuhong/p/5885073.html Python 正则表达式入门(初级篇) 本文主要为没有使用正则表达式经验的新手入门所写. ...
- [Python]有关pygame库中的flip和update的区别
pygame.display.flip()和pygame.display.update()的用法上的区别: 资料一. 资料二. (资料最后更新时间:2019年1月9日)
- DFS、栈、双向队列:CF264A- Escape from Stones
题目: Squirrel Liss liv Escape from Stonesed in a forest peacefully, but unexpected trouble happens. S ...
- IQueryable与IEnumerable区别
前者可以延迟加载,即执行完后不马上执行数据库语句,用到再加载.