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(生成树计数+判断点是否在线段上)的更多相关文章

  1. HDU - 4305 - Lightning 生成树计数 + 叉积判断三点共线

    HDU - 4305 题意: 比较裸的一道生成树计数问题,构造Krichhoof矩阵,求解行列式即可.但是这道题还有一个限制,就是给定的坐标中,两点连线中不能有其他的点,否则这两点就不能连接.枚举点, ...

  2. 高德地图API开发二三事(一)如何判断点是否在折线上及引申思考

    最近使用高德地图 JavaScript API 开发地图应用,提炼了不少心得,故写点博文,做个系列总结一下,希望能帮助到LBS开发同胞们. 项目客户端使用高德地图 JavaScript API,主要业 ...

  3. BZOJ1494 [NOI2007]生成树计数

    题意 F.A.Qs Home Discuss ProblemSet Status Ranklist Contest 入门OJ ModifyUser  autoint Logout 捐赠本站 Probl ...

  4. 【BZOJ1494】【NOI2007】生成树计数(动态规划,矩阵快速幂)

    [BZOJ1494][NOI2007]生成树计数(动态规划,矩阵快速幂) 题面 Description 最近,小栋在无向连通图的生成树个数计算方面有了惊人的进展,他发现: ·n个结点的环的生成树个数为 ...

  5. [BZOJ1494]生成树计数

    [BZOJ1494] [NOI2007]生成树计数 Description 最近,小栋在无向连通图的生成树个数计算方面有了惊人的进展,他发现:·n个结点的环的生成树个数为n.·n个结点的完全图的生成树 ...

  6. 【BZOJ1002】【FJOI2007】轮状病毒(生成树计数)

    1002: [FJOI2007]轮状病毒 Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 1766  Solved: 946[Submit][Status ...

  7. SPOJ 104 HIGH - Highways 生成树计数

    题目链接:https://vjudge.net/problem/SPOJ-HIGH 解法: 生成树计数 1.构造 基尔霍夫矩阵(又叫拉普拉斯矩阵) n阶矩阵 若u.v之间有边相连 C[u][v]=C[ ...

  8. Luogu P5296 [北京省选集训2019]生成树计数

    Luogu P5296 [北京省选集训2019]生成树计数 题目链接 题目大意:给定每条边的边权.一颗生成树的权值为边权和的\(k\)次方.求出所有生成树的权值和. 我们列出答案的式子: 设\(E\) ...

  9. Loj 2320.「清华集训 2017」生成树计数

    Loj 2320.「清华集训 2017」生成树计数 题目描述 在一个 \(s\) 个点的图中,存在 \(s-n\) 条边,使图中形成了 \(n\) 个连通块,第 \(i\) 个连通块中有 \(a_i\ ...

随机推荐

  1. 使用JavaScript判断手机是处于横屏还是竖屏

    移动端的浏览器一般都支持window.orientation这个参数,通过这个参数可以判断出手机是处在横屏还是竖屏状态.从而根据实际需求而执行相应的程序.通过添加监听事件onorientationch ...

  2. lintcode: Missing String

    Missing String  描述: Given two strings, you have to find the missing string. Have you met this questi ...

  3. 利用maven进行项目管理

    下面为maven项目管理的一个结构 首先pom是路径文件,我们在编译或是运行程序时调用到jdk或一些自己写的jar包时会需要指明物理路径,这里的pom是一样的道理,同时在maven的管理下多出来了一些 ...

  4. Ext JS 6学习文档-第3章-基础组件

    Ext JS 6学习文档-第3章-基础组件 基础组件 在本章中,你将学习到一些 Ext JS 基础组件的使用.同时我们会结合所学创建一个小项目.这一章我们将学习以下知识点: 熟悉基本的组件 – 按钮, ...

  5. 从hive导入到oracle(Hcatalog)

    1.使用catalog的情况下: sqoop export --table tableName2 \ #oracle表 --connect jdbc:oracle:thin:@127.0.0.1:15 ...

  6. python中spilt()函数和os.path.spilt()函数区别

    Python中有split()和os.path.split()两个函数: split():拆分字符串.通过指定分隔符对字符串进行切片,并返回分割后的字符串列表. os.path.split():将文件 ...

  7. es6从零学习(三):Class的基本用法

    es6从零学习(三):Class的基本用法 一:定义一个类 //定义类 class Point { constructor(x, y) { this.x = x; this.y = y; } toSt ...

  8. 11.24Daily Scrum(3)

    人员 任务分配完成情况 明天任务分配 王皓南 实现网页上视频浏览的功能.研究相关的代码和功能.1002 数据库测试 申开亮 实现网页上视频浏览的功能.研究相关的代码和功能.1003 实现视频浏览的功能 ...

  9. 总结python 元组和列表的区别

    python的基本类型中有元组和列表这么俩个,但是这哥俩却比较难于区分,今天就来用简单的实例说明两者的不同. 列表:1.使用中括号([ ])包裹,元素值和个数可变 实例: aaa = ['sitena ...

  10. Tomcat服务器学习和使用(一)

    一.Tomcat服务器端口的配置 Tomcat的所有配置都放在conf文件夹之中,里面的server.xml文件是配置的核心文件. 如果想修改Tomcat服务器的启动端口,则可以在server.xml ...