【NOIP2013 Simulation】Missile Defense Tower

topic

Freda's Castle——
"Freda, some intruders were found outside the castle!"
"Meow...I just finished exploring the plans for the construction of the castle, I need to rest for a while, lala~"
"But the intruders are approaching the castle!"
"Don't worry, rainbow, you see, this is the missile defense system I just designed~"
"Hey...don't be cute..."
Freda controls N towers that can launch missiles. Each tower has a sufficient number of missiles, but each tower can only fire one at a time. When a missile is fired, it takes T1 seconds for the missile to come out of the turret, and after the missile is fired, the turret that fires this missile takes T2 minutes to cool down.
All missiles have the same constant flight speed V, and will follow the shortest path to hit the target. When calculating the distance from the turret to the target, you only need to calculate the horizontal distance and ignore the altitude of the missile. The time the missile is in the air is (Distance/V) minutes, and the missile can be destroyed as soon as it reaches the target.
Now, given the coordinates of N missile defense towers, and the coordinates of M intruders, T1, T2, and V, you need to find at least how many minutes it will take to repel all intruders.

analyze

First divide the time, then, you can divide each defense tower into g points, g indicates how many missiles can be launched in the divided time, and then compare each divided point with each intruder, if this Click to wipe off the invader within the time divided by two, and connect them to one side.
Then. . .
Just match it up to the max!
Maximum matching can use network flow or Hungary, if it is not too troublesome, use network flow.

#include <cmath>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <queue>
const int maxlongint=2147483647;
using namespace std;
double t1,t2,v,a[60][60],lf[60][3],xhm[60][3];
int n,m,tot,next[800000],to[800000],last[1000000],xyl[800000];
bool used[800000];
double dis(double x,double y,double x1,double y1)
{
    return sqrt((x1-x)*(x1-x)+(y1-y)*(y1-y));
}
int bj(int x,int y)
{
    next[++tot]=last[x];
    last[x]=tot;
    to[tot]=y;
}
bool find(int x)
{
    int i,j,k,l;
    for(i=last[x];i;i=next[i])
    {
        j=to[i];
        if(!used[j])
        {
            used[j]=true;
            if(xyl[j]==0 || find(xyl[j]))
            {
                xyl[j]=x;
                return true;
            }
        }
    }
    return false;
}
bool ddx(double limit)
{
    int i,j,k,l;
    double cs=(limit-t1)/(t1+t2)+1;
    tot=0;
    memset(to,0,sizeof(to));
    memset(last,0,sizeof(last));
    memset(next,0,sizeof(next));
    for(i=1;i<=n;i++)
        for(j=0;j<int(cs);j++)
        {
            double time=j*(t1+t2)+t1;
            for(k=1;k<=m;k++)
            {
                if(time+a[i][k]<=limit)
                {
                    bj(int(n*j+i),int(cs*n+k));
                    bj(int(cs*n+k),int(n*j+i));
                }
            }
        }
    int ans=0;
    memset(xyl,0,sizeof(xyl));
    for(i=1;i<=int(n*cs+m);i++)
    {
        memset(used,0,sizeof(used));
        if(find(i)) ans++;
    }
    return ans==m*2;
}
double rf()
{
    double l=0,r=50000,mid;
    int i,j,k;
    for(i=1;i<=50;i++)
    {
        mid=(l+r)/2;
        if(ddx(mid)) r=mid; 
        else l=mid;
    }
    return r;
}
int main()
{
    scanf("%d%d%lf%lf%lf",&n,&m,&t1,&t2,&v);
    t1=t1/60;
    int i,j,k,l,x,y;
    for(i=1;i<=m;i++)
    {
        scanf("%lf%lf",&xhm[i][1],&xhm[i][2]);
    }
    for(i=1;i<=n;i++)
    {
        scanf("%lf%lf",&lf[i][1],&lf[i][2]);
    }
    for(i=1;i<=n;i++)
        for(j=1;j<=m;j++)
        {
            a[i][j]=dis(lf[i][1],lf[i][2],xhm[j][1],xhm[j][2])/v;
        }
    double ans;
    ans=rf();
    printf("%.6lf",ans);
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325847576&siteId=291194637