HDU 4350 (生成树计数 判断点在线段上)

Lightning

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1781    Accepted Submission(s): 607


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
 


题意:平面上有n个sb,然后某一个变身,他会导致距离离他r之内的sb也变身

(他和这个sb之间不能有别的sb),两个相互影响的sb之间连线,最后这种图的形状

有几种.

建图的时候n^3枚举判断两个sb之间有没有别的sb,没有这两个点就可以连边,然后

跑一下生成树计数.貌似没什么坑.

#include <bits/stdc++.h>
using namespace std;
#define maxn 311
#define mod 10007

#define eps 1e-10
int a[maxn][maxn];
int cnt;
int n;
double r;

struct point {
    double x, y;
    point (double _x = 0, double _y = 0) : x(_x), y(_y) {}
    point operator - (point a) const {
        return point (x-a.x, y-a.y);
    }
    bool operator < (const point &a) const {
        return x < a.x || (x == a.x && y < a.y);
    }
}p[maxn];

int dcmp (double x) {
    if (fabs (x) < eps)
        return 0;
    else return x < 0 ? -1 : 1;
}
double cross (point a, point b) {
    return a.x*b.y-a.y*b.x;
}
double dot (point a, point b) {
    return a.x*b.x + a.y*b.y;
}
bool OnSegment (point a1, point a2, point p) {//判断点p是不是在线段a1a2上
    if (dcmp (cross (a1-p, a2-p)) == 0 && dcmp (dot (a1-p, a2-p)) <= 0)
        return 1;
    return 0;
}

long long det ()        //按列化为下三角
{
     long long res = 1;
     for(int i = 0; i < n; ++i)
     {
         if (!a[i][i])
         {
             bool flag = false;
             for (int j = i + 1; j < n; ++j)
             {
                 if (a[j][i])
                 {
                     flag = true;
                     for (int k = i; k < n; ++k)
                     {
                         swap (a[i][k], a[j][k]);
                     }
                     res = -res;
                     break;
                 }
             }

             if (!flag)
             {
                 return 0;
             }
         }

         for (int j = i + 1; j < n; ++j)
         {
             while (a[j][i])
             {
                 long long t = a[i][i] / a[j][i];
                 for (int k = i; k < n; ++k)
                 {
                     a[i][k] = (a[i][k] - t * a[j][k]) % mod;
                     swap (a[i][k], a[j][k]);
                 }
                 res = -res;
             }
          }
          res *= a[i][i];
          res %= mod;
      }
      return (res+mod)%mod;
}

double dis (point a, point b) {
    double x = a.x-b.x, y = a.y-b.y;
    return x*x+y*y;
}

int main()
{
    //freopen("in.txt", "r", stdin);
    int t;
    scanf ("%d", &t);
    while (t--) {
        scanf ("%d%lf", &n, &r);
        for (int i = 0; i < n; i++) {
            scanf ("%lf%lf", &p[i].x, &p[i].y);
        }
        memset (a, 0, sizeof a);
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) if (i != j) {
                if (dis (p[i], p[j]) > r*r)
                    continue;
                bool flag = 0;
                for (int k = 0; k < n; k++) if (k != i && k != j) {
                    if (OnSegment (p[i], p[j], p[k])) {
                        flag = 1;
                        break;
                    }
                }
                if (!flag) {
                    a[i][i]++;
                    a[i][j] = -1;
                }
            }
        }
        n--;
        long long ans = det ();
        printf ("%lld\n", (ans > 0 ? ans : -1));
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值