3126 Nova //2009 Asia Wuhan Regional Contest Online //MAXMATCH

Nova

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 564    Accepted Submission(s): 134


Problem Description
The Lich is a powerful hero that he can kill a wisp with his skill Frost Nova. The Burning Legion wants to conquer the forest so they sent some liches to kill all the wisps. A lich can kill a wisp once he could see the wisp and the wisp in his attack range. So the lich can attack a wisp when the distance between them is less than or equal to specific R and no trees are on the segment between the lich and wisp. Each lich has a cool down time that once he used Frost Nova he has to wait a few seconds for the next attack. Different liches may have different attack range and cool down time. The Lich King is the leader of the Burning Legion and he wants to arrange the attack order so the liches can wipe out all the wisps as soon as possible.
 

Input
The first line consists of an integer T, indicating the number of test cases.
The first line of each case consists of three integers N, M, K, indicating the number of lich, the number of wisps and the number of trees. The next N lines, each line consists of four integers x, y, r, t indicating the coordinate of that a lich, the radius of the attack range that lich’s Frost Nova can reach and the value of cool down time. The next M lines, each line consists of two integers x, y indicating the coordinate of each wisp. The last K lines, each line consists of three integers x, y, r, indicating the coordinate and radius of a tree. A lich cannot attack a wisp if the segment between them has a common point with the tree. The lich, wisp and trees will not overlap with each other.
 

Output
Output the minimum time lich need to kill all the wisps on a single line, or -1 if lich cannot kill all the wisps.

Constrains
0 < T <= 20
0 <= N, M, K <= 200
-10000 <= x, y <= 10000
0 <= r, t <= 10002
 

Sample Input
  
  
1 2 3 1 -100 0 100 3 100 0 100 5 -100 -10 100 10 110 11 5 5 10
 

Sample Output
  
  
5
 

Source
 

Recommend
lcy

 

 

 

#include<cstdio>

#include<cstring>

#include<cmath>

const int maxint = 0x7FFFFFFF;

const int maxn = 200 + 5;

const double eps = 1e-8;

int sgn(double x)

{

    return (x>eps) - (x<-eps);

}

struct Point

{

    double x, y;

    Point() {}

    Point(double _x, double _y): x(_x), y(_y) {}

    Point operator + (const Point &a) const { return Point(x + a.x, y + a.y);}

    Point operator - (const Point &a) const { return Point(x - a.x, y - a.y);}

    double operator * (const Point &a) const{ return x * a.y - y * a.x;}

    double dot(const Point &a) const{ return x * a.x + y * a.y; }

    double lenth() const { return sqrt(dist());}

    double dist() const { return x * x + y * y;}

    void input(){ scanf("%lf%lf", &x, &y);}

    void output() const{ printf("%lf %lf/n", x, y);}

};

int mat[maxn], now[maxn], r[maxn], t[maxn], br[maxn];

bool used[maxn], g[maxn][maxn];

int n, m, c;

Point lich[maxn], tree[maxn], wisp[maxn];

double cross(const Point &a, const Point &b, const Point &c)

{

    return (b-a)*(c-a);

}

bool nova(const Point &a, const Point &b, double r)

{

    if (sgn((a-b).dist()-r*r)>0) return false;

    for (int i=0;i<c;++i)

    {

        if (sgn(fabs(cross(a,b,tree[i])) / (a-b).lenth()-br[i]) > 0) continue;

        if (sgn((tree[i]-a).dot(b - a))<0 || sgn((tree[i]-b).dot(a-b))<0) continue;

        return false;

    }

    return true;

}

bool find(int x)

{

    for(int i=0;i<m;i++)

    if(!used[i] && g[x][i])

    {

        used[i]=true;

        if(mat[i]==-1 || find(mat[i]) )

        {

            mat[i]=x;

            return true;

        }

    }

    return false;

}

void match()

{

    memset(mat,-1,sizeof(mat));

    memset(now,0,sizeof(now));

    int cnt=0,ans=0;

    while(cnt<m)

    {

        int v=-1;

        for(int i=0;i<n;++i)

        {

            if(now[i]==maxint) continue;

            if(v==-1 || now[i]<now[v] ) v=i;

        }

        if(v==-1) break;

        memset(used,0,sizeof(used));

        if(find(v))

        {

            ans=now[v];

            now[v]+=t[v];

            cnt++;

        }

        else now[v]=maxint;

    }

    if (cnt == m) printf("%d/n", ans);

    else printf("-1/n");

}

int main()

{

    int T;

    scanf("%d",&T);

    while(T--)

    {

        scanf("%d%d%d",&n,&m,&c);

        for(int i=0;i<n;i++)

        {

            lich[i].input();

            scanf("%d%d",&r[i],&t[i]);

        }

        for(int i=0;i<m;i++) wisp[i].input();

        for(int i=0;i<c;i++)

        {

            tree[i].input();

            scanf("%d",&br[i]);

        }

        for(int i=0;i<n;i++)

          for(int j=0;j<m;j++)

          g[i][j]=nova(lich[i],wisp[j],r[i]);

        match();

    }

    return 0;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值