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\ ...
随机推荐
- leetcode-分割回文子串
给定一个字符串 s,将 s 分割成一些子串,使每个子串都是回文串. 返回 s 所有可能的分割方案. 示例: 输入: "aab" 输出: [ ["aa",&quo ...
- 开源自动驾驶仿真平台 AirSim (2) - 编译 AirSim
AirSim 的官方 Github: https://github.com/Microsoft/AirSim 对于 Unreal Engine 来说,AirSim 其实是作为一个插件存在,说白了就是把 ...
- 单源最短路——dijkstra算法
Dijkstra算法 1.定义概览 Dijkstra(迪杰斯特拉)算法是典型的单源最短路径算法,用于计算一个节点到其他所有节点的最短路径.主要特点是以起始点为中心向外层层扩展,直到扩展到终点为止. 问 ...
- DAY2敏捷冲刺
站立式会议 工作安排 (1)服务器配置 (2)数据库连接 (3)页面创意 燃尽图 代码提交记录 感想 林一心:centos配置服务器真的算是一个不小的坑,目前数据库配置清楚,脚本部署好明天测试交互,还 ...
- Javascript动态方法调用与参数修改的问题
Javascript中可以对所传参数在函数内进行修改,如下 ? 1 2 3 4 5 function func1(name) { name = 'lily'; alert(name); ...
- Uncaught ReferenceError: wx is not defined
程序的分享功能调用了微信的接口,但是忽然发现就报这个错误, Uncaught ReferenceError: wx is not defined 同时下方还有这个错误 This content sho ...
- Firefox火狐浏览器 修改默认搜索引擎
如图:
- centos设置时间同步
1.安装ntpdate #yum install ntpdate 2. #cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime #ntpdate ...
- Python自定义包在linux服务器导入错误的解决办法
在本地机器上跑python代码,自己定义的文件进行导包运行是没有问题,但是放到linux服务器上的时候就会提示 ImportError:No module named xxxx(要导入的文件包名) 在 ...
- 整理下本周工作中遇到的疑问;uid/euid/suid;docker镜像管理
1.系统中的父子进程关系,以及docker是如何处理的这种父子进程关系,线上问题发现,子进程长时间得不到退出. 2.调用system系统调用发生了啥事情,发现大量的页表拷贝. 3.通过shell命令通 ...