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-帕斯卡三角形
帕斯卡三角形 给定一个非负整数 numRows,生成杨辉三角的前 numRows 行. 示例: 输入: 5 输出: [ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4 ...
- 油田 (Oil Deposits UVA - 572)
题目描述: 原题:https://vjudge.net/problem/UVA-572 题目思路: 1.图的DFS遍历 2.二重循环找到相邻的八个格子 AC代码: #include <iostr ...
- [Clr via C#读书笔记]Cp13接口
Cp13接口 类和接口继承 接口只提供签名,不提供实现:等效于契约:凡事能使用具名接口的地方都能够使用实现了的接口. 定义接口 定义很简单,FCL也提供了大量的现成接口供使用: 继承接口 类不能多继承 ...
- Python基础 之 list类-列表
list类-列表 一.list类的基本属性 1. 列表格式 li = [1, 12, 9, ", 10], "even"], "root", True ...
- 第四次作业之psp
psp 进度条 博文字数累积折线图 代码行数累积折线图 psp饼状图
- 11.24Daily Scrum
人员 任务分配完成情况 明天任务分配 王皓南 实现网页上视频浏览的功能.研究相关的代码和功能.990 测试 申开亮 实现网页上视频浏览的功能.研究相关的代码和功能.991 测试 王宇杰 负责后台代码测 ...
- ueditor百度编辑器的赋值方法
示例: http://ueditor.baidu.com/website/onlinedemo.html 引用代码: window.UMEDITOR_HOME_URL = $CONFIG['domai ...
- python学习摘要(3)--字符串处理函数
python没有字符类型, "字符串" '字符串' '''字符串''' """字符串""" 三引号可以支持字符串跨行 字 ...
- Alpha冲刺——第四天
Alpha第四天 听说 031502543 周龙荣(队长) 031502615 李家鹏 031502632 伍晨薇 031502637 张柽 031502639 郑秦 1.前言 任务分配是VV.ZQ. ...
- a2
Alpha 冲刺报告 队名: 组长:吴晓晖 今天完成了哪些任务: 代码量300+,完成了百度地图API的引入. 展示GitHub当日代码/文档签入记录: 明日计划: 整理下这两个功能,然后补些bug ...