Lightning
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1588 Accepted Submission(s): 525
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
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
Author
BUPT
Source
2012 Multi-University Training Contest 1
/* *********************************************** Author :CKboss Created Time :2015年04月29日 星期三 08时23分56秒 File Name :HDOJ4305.cpp ************************************************ */ #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <string> #include <cmath> #include <cstdlib> #include <vector> #include <queue> #include <set> #include <map> using namespace std; typedef long long int LL; const int maxn=500; const LL MOD=10007; int n,R; struct Point { int x,y; }pt[maxn]; int Dist(Point a,Point b) { return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y); } LL a[maxn][maxn],b[maxn][maxn]; LL inv(LL a,LL m) { if(a==1) return 1; return inv(m%a,m)*(m-m/a)%m; } LL det(LL a[][maxn],int n) { for(int i=0;i<n;i++) for(int j=0;j<n;j++) b[i][j]=(a[i][j]+MOD)%MOD; int res=1; for(int i=0;i<n;i++) { for(int j=i;j<n;j++) { if(b[j][i]!=0) { for(int k=i;k<n;k++) swap(b[i][k],b[j][k]); if(i!=j) res=(MOD-res)%MOD; break; } } if(b[i][i]==0) { res=-1; break; } for(int j=i+1;j<n;j++) { LL mut=(b[j][i]*inv(b[i][i],MOD))%MOD; for(int k=i;k<n;k++) b[j][k]=(b[j][k]-(b[i][k]*mut)%MOD+MOD)%MOD; } res=(res*b[i][i])%MOD; } return res; } inline int Dot(Point a,Point b) { return a.x*b.x+a.y*b.y; } inline int Cross(Point a,Point b) { return a.x*b.y-a.y*b.x; } bool onSeg(Point p,Point a1,Point a2) { Point A=(Point){a1.x-p.x,a1.y-p.y}; Point B=(Point){a2.x-p.x,a2.y-p.y}; return Cross(A,B)==0&&Dot(A,B)<0; } int main() { //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); int T_T; scanf("%d",&T_T); while(T_T--) { scanf("%d%d",&n,&R); for(int i=0;i<n;i++) { int x,y; scanf("%d%d",&x,&y); pt[i]=(Point){x,y}; } memset(a,0,sizeof(a)); for(int i=0;i<n;i++) { for(int j=i+1;j<n;j++) { if(i==j) continue; if(Dist(pt[i],pt[j])<=R*R) { /// i--->j /// check bool flag=true; for(int k=0;k<n&&flag;k++) { if(k==j||k==i) continue; flag=!onSeg(pt[k],pt[i],pt[j]); } if(flag==false) continue; a[i][i]++; a[i][j]=-1; a[j][j]++; a[j][i]=-1; } } } LL ans=det(a,n-1); printf("%I64d\n",ans); } return 0; }