首页 > 学院 > 开发设计 > 正文

HDU 4305 Lightning

2019-11-08 18:37:16
字体:
来源:转载
供稿:网友
PRoblem DescriptionThere 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. InputThere 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. OutputOne 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 AuthorBUPT Source2012 Multi-University Training Contest 1 Recommendzhuyuanchen520~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~行列式求生成树个数~调到吐血……还是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;}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表