HDU4305:Lightning(生成树计数+判断点是否在线段上)
Lightning
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2465 Accepted Submission(s): 912
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4305
Description:
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.
Input:
There 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.
Output:
One 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
题意:
在一个二维平面中给出每个人的坐标,问有多少种方式能让所有人都被雷p。
被雷p还有条件,假如第i个人被p了,离他不超过R距离的人也都会被P,并且他们之中没有其它人。
题解:
为什么这么丧心病狂要算有多少种方式能让所有人都被p。。
做法就是按照条件建边,然后就是生成树计数裸题了。。
代码如下:
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <cmath>
using namespace std;
typedef long long ll;
const int N = ,MOD = ;
int t;
int n,r;
struct Point{
int x,y;
}p[N];
double dis(int x,int y){
return sqrt((double)(p[x].x-p[y].x)*(p[x].x-p[y].x)+(double)(p[x].y-p[y].y)*(p[x].y-p[y].y));
}
int check(int p1,int p2){
int x1=min(p[p1].x,p[p2].x),x2=max(p[p1].x,p[p2].x);
if(x1==x2){
for(int i=;i<=n;i++){
if(i==p1||i==p2) continue ;
if(p[i].x==x1){
if(p[i].y>=min(p[p1].y,p[p2].y) && p[i].y<=max(p[p1].y,p[p2].y)) return ;
}
}
return ;
}
for(int i=;i<=n;i++){
if(i==p1||i==p2||p[i].x<x1||p[i].x>x2) continue ;
double K = (double)(p[p2].y-p[p1].y)/(p[p2].x-p[p1].x);
if(K==(double)(p[p2].y-p[i].y)/(p[p2].x-p[i].x)) return ;
}
return ;
}
ll b[N][N];
int g[N][N];
ll Det(int n){
int i,j,k;
ll ret = ;
for(i=;i<=n;i++){
for(j = i+;j <= n;j++){
while(b[j][i]){
ll tmp=b[i][i]/b[j][i];//不存在除不尽的情况
for(k = i;k <= n;k++){
b[i][k] = (b[i][k] - tmp*b[j][k])%MOD;
if(b[i][k]<) b[i][k]+=MOD;
}
swap(b[i],b[j]);
ret = -ret;
}
}
if(!b[i][i]) return -;
ret = ret * b[i][i]%MOD;
}
if(ret < ) ret += MOD;
return ret;
}
int main(){
scanf("%d",&t);
while(t--){
scanf("%d%d",&n,&r);
memset(g,,sizeof(g));
memset(b,,sizeof(b));
for(int i=;i<=n;i++) scanf("%d%d",&p[i].x,&p[i].y);
for(int i=;i<=n;i++){
for(int j=;j<=n;j++){
if(i==j) continue ;
if(check(i,j)&&dis(i,j)<=r) g[i][j]=g[j][i]=;
}
}
for(int i=;i<=n;i++){
for(int j=i+;j<=n;j++){
if(g[i][j]){
b[i][i]++;b[j][j]++;
b[i][j]=b[j][i]=-;
}
}
}
cout<<Det(n)<<endl;
}
return ;
}
HDU4305:Lightning(生成树计数+判断点是否在线段上)的更多相关文章
- HDU - 4305 - Lightning 生成树计数 + 叉积判断三点共线
HDU - 4305 题意: 比较裸的一道生成树计数问题,构造Krichhoof矩阵,求解行列式即可.但是这道题还有一个限制,就是给定的坐标中,两点连线中不能有其他的点,否则这两点就不能连接.枚举点, ...
- 高德地图API开发二三事(一)如何判断点是否在折线上及引申思考
最近使用高德地图 JavaScript API 开发地图应用,提炼了不少心得,故写点博文,做个系列总结一下,希望能帮助到LBS开发同胞们. 项目客户端使用高德地图 JavaScript API,主要业 ...
- BZOJ1494 [NOI2007]生成树计数
题意 F.A.Qs Home Discuss ProblemSet Status Ranklist Contest 入门OJ ModifyUser autoint Logout 捐赠本站 Probl ...
- 【BZOJ1494】【NOI2007】生成树计数(动态规划,矩阵快速幂)
[BZOJ1494][NOI2007]生成树计数(动态规划,矩阵快速幂) 题面 Description 最近,小栋在无向连通图的生成树个数计算方面有了惊人的进展,他发现: ·n个结点的环的生成树个数为 ...
- [BZOJ1494]生成树计数
[BZOJ1494] [NOI2007]生成树计数 Description 最近,小栋在无向连通图的生成树个数计算方面有了惊人的进展,他发现:·n个结点的环的生成树个数为n.·n个结点的完全图的生成树 ...
- 【BZOJ1002】【FJOI2007】轮状病毒(生成树计数)
1002: [FJOI2007]轮状病毒 Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 1766 Solved: 946[Submit][Status ...
- SPOJ 104 HIGH - Highways 生成树计数
题目链接:https://vjudge.net/problem/SPOJ-HIGH 解法: 生成树计数 1.构造 基尔霍夫矩阵(又叫拉普拉斯矩阵) n阶矩阵 若u.v之间有边相连 C[u][v]=C[ ...
- Luogu P5296 [北京省选集训2019]生成树计数
Luogu P5296 [北京省选集训2019]生成树计数 题目链接 题目大意:给定每条边的边权.一颗生成树的权值为边权和的\(k\)次方.求出所有生成树的权值和. 我们列出答案的式子: 设\(E\) ...
- Loj 2320.「清华集训 2017」生成树计数
Loj 2320.「清华集训 2017」生成树计数 题目描述 在一个 \(s\) 个点的图中,存在 \(s-n\) 条边,使图中形成了 \(n\) 个连通块,第 \(i\) 个连通块中有 \(a_i\ ...
随机推荐
- 《Effective C++》读书笔记 条款03 尽可能使用const 使代码更加健壮
如果你对const足够了解,只需记住以下结论即可: 将某些东西声明为const可帮助编译器侦测出错误用法,const可被施加于任何作用于内的对象.函数参数.函数返回类型.成员函数本体. 编译器强制实施 ...
- 查找 二叉树中 k1 到 k2区间的节点
vector<int> res; int key1, key2; void traverse(TreeNode * root){//采用前序遍历 if(root == NULL) retu ...
- 【Linux 运维】Centos7初始化网络配置
设置网络 (1)动态获取一个IP地址 #dhclient 系统自动自动获取一个IP地址#ip addr 查看获取的ip地址(2)查看网关,子网掩码 虚拟机编辑>虚拟 ...
- Halcon介绍和下载安装视频教程
------------------------Halcon,Visionpro高清视频教程,点击下载视频--------------------------
- 从SDN鼻祖Nicira到VMware NSX 网络虚拟化平台的简单探讨
以前的大二层技术,一般是在物理网络底层使用IS-IS路由技术,再在此基础之上,实现数据中心网络的二层扩展,如公有的Trill.SPB技术和Cisco私有的OTV.Fabricpath技术:前沿一些的网 ...
- SpringBoot在IDEA下使用JPA
1依赖 使用IDEA构建基于JPA的项目需要引用JPA.MYSQL依赖 2配置文件修改 2.1连接库 spring.datasource.url=jdbc:mysql://localhost:3306 ...
- [原创]Docker学习记录: Shipyard+Swarm+Consul+Service Discover 搭建教程
网上乱七八糟的资料实在是太多了, 乱, 特别乱, 而看书呢, 我读了2本书, 一本叫做<>, 另一本叫做<< Docker进阶与实战>> 在 服务发现这块讲的又不清 ...
- Python3 数据类型-集合
在Python中集合set是基本数据类型的一种,它有可变集合(set)和不可变集合(frozenset)两种.创建集合set.集合set添加.集合删除.交集.并集.差集的操作都是非常实用的方法. 集合 ...
- c# throw抛出上一个异常
catch(exception e) { throw; } 不仅抛出这次的异常,也抛出之前的异常. 用法示例:函数A调用函数B,A用到此throw时,B中发生的异常也会继承过来. catch(exce ...
- 用纯css改变下拉列表select框的默认样式(转)
用纯css改变下拉列表select框的默认样式 分享到 分类 JS学习 关键字 前端 发布 kris 2015-04-01 注意 转载须保留原文链接,译文链接,作者译者等信息. 在这 ...