再探 3126 Nova //二分逼近+多重匹配

来源:互联网 发布:mysql 创建唯一索引 编辑:程序博客网 时间:2024/06/02 07:18

Nova

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

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<stdio.h>
#include<string.h>
#include<math.h>
const int maxint=1<<30-1;
const double eps=1e-8;
int sign(double x)
{
    return (x>eps)-(x<-eps);
}
struct  point
{
    double x,y;
    point() {}
    point(double xx,double yy):x(xx),y(yy) {}
    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 dist() const { return x*x+y*y;}
    double length() const { return sqrt(dist()); }
    void input()  {  scanf("%lf%lf",&x,&y); }
    void output() const {  printf("%lf %lf/n",x,y);}
}lich[201],wisp[201],tree[201];

int link[201][201];
int n,m,k,tmax;
bool flag,used[201];
int r[201],t[201],tr[201],tnow[201];
bool g[201][201];

bool can(int t)
{
    for(int i=0;i<n;i++)
    {
        if(used[i]==0&&g[i][t])
        {
            used[i]=1;
            if(link[i][0]<tnow[i])
            {
                link[i][++link[i][0]]=t;
                return true;
            }
            else
            {
                for(int j=1; j<=link[i][0]; j++)
                    if(can(link[i][j]))
                    {
                        link[i][j]=t;
                        return true;
                    }
            }
        }
    }
    return false;
}

bool MaxMatch(int x)
{
    for(int i=0;i<n;i++) tnow[i]=x/t[i]+1;
    for(int i=0;i<n;i++) link[i][0]=0;
    for(int i=0;i<m;i++)
    {
        memset(used,false,sizeof(used));
        if(!can(i))  return false;
    }
    return true;
}

void solve()
{
    int fir=0,sec=tmax*m;
    int ans=0;
    while(fir<sec)
    {
        int mid=(fir+sec)>>1;
        if(MaxMatch(mid))
        {
            flag=true;
            ans=mid;
            sec=mid;
        }
        else
        fir=mid+1;
    }
    if(flag)  printf("%d/n",ans);
    else printf("-1/n");
}

bool nova(point& a,point& b,int r)
{
    if(sign((a-b).dist()-r*r)>0)  return false;
    for(int i=0;i<k;i++)
    {
        if(sign(fabs((tree[i]-a)*(b-a))/(a-b).length()-tr[i])>0)  continue;
        if(sign((tree[i]-a).dot(b-a))<0 || sign((tree[i]-b).dot(a-b)<0))   continue;
        return false;
    }
    return true;
}

int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        tmax=0;
        flag=false;
        scanf("%d%d%d",&n,&m,&k);
        for(int i=0;i<n;i++)
        {
            lich[i].input();
            scanf("%d%d",&r[i],&t[i]);
            if(t[i]>tmax)  tmax=t[i];
        }
        for(int i=0;i<m;i++)  wisp[i].input();
        for(int i=0;i<k;i++)
        {
            tree[i].input();
            scanf("%d",&tr[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]);
        solve();
    }
    return 0;
}

原创粉丝点击