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

来源:互联网 发布:淘宝卖檀香 编辑:程序博客网 时间:2024/06/15 19:25

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
12 3 1-100 0 100 3100 0 100 5-100 -10100 10110 115 5 10
 

Sample Output
5
 

Source
2009 Asia Wuhan Regional Contest Online
 

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;

}

原创粉丝点击