HDU 4305 Lightning

来源:互联网 发布:mac拼音切换快捷键 编辑:程序博客网 时间:2024/06/03 07:30
Problem 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
33 2-1 00 11 03 2-1 00 01 03 1-1 00 11 0
 

Sample Output
31-1
 

Author
BUPT
 

Source
2012 Multi-University Training Contest 1
 

Recommend
zhuyuanchen520
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
行列式求生成树个数~
调到吐血……还是WA……欢迎神犇帮忙查错……


#include<cstdio>#include<cstring>#include<iostream>#include<cmath>using namespace std;#define zero(u) (u>0 ? u:-u)<1e-15int t,n;bool b[301][301];double a[301][301],r,x[301],y[301];bool che(int u,int v){if((x[u]-x[v])*(x[u]-x[v])+(y[u]-y[v])*(y[u]-y[v])>r*r) return 0;if(x[u]>x[v]) swap(u,v);for(int i=1;i<=n;i++)  if(i!=u && i!=v)  {  if((x[i]-x[u])*(y[i]-y[v])-(x[i]-x[v])*(y[i]-y[u])) continue;  if(x[i]<x[u] || x[i]>x[v]) continue;  return 0;  }return 1;}double cal(){int i,j,k,opi=0;double ans=1;for(i=1;i<=n;i++){if(zero(a[i][i])){for(j=i+1;j<=n;j++) if(!zero(a[j][i])) break;if(j==n+1) return -1;for(k=i;k<=n;k++) swap(a[i][k],a[j][k]);opi++;}ans*=a[i][i];ans=fmod(ans,10007);for(k=i+1;k<=n;k++) a[i][k]/=a[i][i];for(j=i+1;j<=n;j++)  for(k=i+1;k<=n;k++) a[j][k]-=a[j][i]*a[i][k];}if(opi&1) ans=-ans;return ans;}int main(){scanf("%d",&t);while(t--){memset(a,0,sizeof(a));memset(b,0,sizeof(b));scanf("%d%lf",&n,&r);for(int i=1;i<=n;i++) scanf("%lf%lf",&x[i],&y[i]);for(int i=1;i<n;i++)  for(int j=i+1;j<=n;j++)    if(che(i,j)) b[i][j]=b[j][i]=1;for(int i=1;i<=n;i++)  for(int j=1;j<=n;j++) if(b[i][j]) a[i][i]+=1;for(int i=1;i<=n;i++)  for(int j=1;j<=n;j++) if(b[i][j]) a[i][j]=-1;n--;printf("%0.0lf\n",cal());}return 0;}


1 0
原创粉丝点击