博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU4305 Lightning
阅读量:6552 次
发布时间:2019-06-24

本文共 2619 字,大约阅读时间需要 8 分钟。

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

33 2-1 00 11 03 2-1 00 01 03 1-1 00 11 0

Sample Output

31-1

 

题目配图戳中笑点2333

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

 

 

图论 矩阵树定理 模方程

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

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

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

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

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

 

1 /*by SilverN*/  2 #include
3 #include
4 #include
5 #include
6 #include
7 using namespace std; 8 const int mod=10007; 9 const double eps=1e-7; 10 const int mxn=330; 11 int read(){ 12 int x=0,f=1;char ch=getchar(); 13 while(ch<'0' || ch>'9'){
if(ch=='-')f=-1;ch=getchar();} 14 while(ch>='0' && ch<='9'){x=x*10+ch-'0';ch=getchar();} 15 return x*f; 16 } 17 struct block{ 18 int x,y; 19 }a[mxn]; 20 int n,R; 21 int D; 22 int G[mxn][mxn]; 23 bool vis[mxn]; 24 void exgcd(int a,int b,int &x,int &y){
//求逆元用 25 if(!b){x=1;y=0;return;} 26 exgcd(b,a%b,x,y); 27 int t=x;x=y;y=t-a/b*x; 28 return; 29 } 30 int Gauss(){
//Matrix-tree定理 高斯消元 31 int i,j,x,y; 32 int ans=1; 33 for(i=1;i
G[p][i])p=j; 37 if(p==i){ return -1;}//无解 38 for(j=1;j
D)return 0;//距离大于R 64 double k=ck(x,y); 65 for(int i=1;i<=n;i++){ 66 if(i==y || i==x)continue; 67 if(dist(x,i)

 

转载于:https://www.cnblogs.com/SilverNebula/p/6408106.html

你可能感兴趣的文章
List集合具体对象的特点
查看>>
网络信息安全之防火墙***检测方法 (五)
查看>>
常用awk命令(转)
查看>>
怎样为用户写“招标书”
查看>>
1.7 文件目录管理及相关的命令使用方法
查看>>
实际案例告诉你大数据在农业中如何应用
查看>>
LAMP优化策略
查看>>
PDF中添加页面/合并 PDF 内容
查看>>
JS仿FLASH特效可跳转回首页的CSS二级联动菜单
查看>>
页面导入样式时,使用link和@import有什么区别?
查看>>
关于php语言的使用!
查看>>
类成员与类的实例成员
查看>>
Spark源码编译并在YARN上运行WordCount实例
查看>>
Spring AOP + AspectJ annotation example
查看>>
Spring VS EJB 3 的若干认识误区(转)
查看>>
数据归一化和两种常用的归一化方法
查看>>
React.js初探(一)
查看>>
Neo4j CQL -(17)- NULL值
查看>>
BZOJ4554: [Tjoi2016&Heoi2016]游戏 luoguP2825 loj2057
查看>>
json_encode后的中文不编码成unicode
查看>>