AcWing 374 bipartito + gráfico bipartito coincidencia máxima

Título

Portal Acwing 374 torre de defensa antimisiles

respuesta

El momento de repeler al intruso satisface la monotonicidad, y la respuesta es dicotómica. Se transforma en un problema de asignación, y el intruso se considera el nodo izquierdo, y la tupla de dos de la torre de defensa y el tiempo de lanzamiento se considera el nodo derecho. Si la torre defensiva T 1 + k × (T 1 + T 2), k ≥ 0 T_1 + k \ times (T_1 + T_2), k \ geq 0T1+k×( T1+T2) ,kLos proyectiles disparados a las 0 en punto pueden repeler a los invasores y están conectados entre la torre defensiva y los invasores. Encuentre la máxima coincidencia del gráfico bipartito y determine si es igual aMMM es suficiente.

La máxima complejidad de tiempo de coincidencia de resolver gráficos bipartitos en un solo tiempo O (VE) O (VE)O ( V E ) ,O (N 5) O (N ^ 5) enesta preguntaO ( N5 )Evidentemente, es difícil hacer el trabajo. Observe que el nodo izquierdo esO (N) O (N)O ( N ) , el nodo de la derecha esO (N 2) O (N ^ 2)O ( N2 ), luego elDFS DFSizquierdocon elmenor número de nodosD F S está buscando una ruta aumentada. En este momento, la máxima complejidad de tiempo de coincidencia de resolver el gráfico bipartito en un solo tiempo esO (N 4) O (N ^ 4)O ( N4 ). Complejidad de tiempo totalO (N 4 log ⁡ [(T 1 + T 2) × M]) O (N ^ 4 \ log [(T_1 + T_2) \ times M])O ( N4lo g [ ( T1+T2)×M ] )

Tenga en cuenta que T 1 T_1T1La unidad es segundos, T 2 T_2T2 La unidad son minutos.

#include <bits/stdc++.h>
using namespace std;
const int maxn = 55, maxv = maxn + maxn * maxn, maxe = maxn * maxn * maxn;
const double eps = 1e-8;
int N, M, V, match[maxv];
int X1[maxn], Y1[maxn], X2[maxn], Y2[maxn];
int tot, head[maxv], to[maxe], nxt[maxe];
double T1, T2, T3[maxn][maxn];
bool vs[maxn];

inline void add(int x, int y)
{
    
    
    to[++tot] = y, nxt[tot] = head[x], head[x] = tot;
}

bool dfs(int x)
{
    
    
    vs[x] = 1;
    for (int i = head[x]; i; i = nxt[i])
    {
    
    
        int y = to[i], z = match[y];
        if (!z || (!vs[z] && dfs(z)))
        {
    
    
            match[y] = x;
            return 1;
        }
    }
    return 0;
}

bool judge(double x)
{
    
    
    memset(head, 0, sizeof(head));
    tot = 0;
    int t = (x - T1) / (T1 + T2) + 1;
    for (int i = 1; i <= M; ++i)
        for (int j = 1; j <= N; ++j)
        {
    
    
            double r = x - T3[i][j] - T1;
            int cnt = r / (T1 + T2) + (r >= 0);
            for (int k = 1, x, y; k <= cnt; ++k)
                x = i, y = (j - 1) * t + k + M, add(x, y), add(y, x);
        }
    memset(match, 0, sizeof(match));
    int res = 0;
    for (int i = 1; i <= M; ++i)
        memset(vs, 0, sizeof(vs)), res += dfs(i);
    return res == M;
}

int main()
{
    
    
    scanf("%d%d%lf%lf%d", &N, &M, &T1, &T2, &V);
    T1 /= 60;
    for (int i = 1; i <= M; ++i)
        scanf("%d%d", X1 + i, Y1 + i);
    for (int i = 1; i <= N; ++i)
        scanf("%d%d", X2 + i, Y2 + i);
    for (int i = 1; i <= M; ++i)
        for (int j = 1; j <= N; ++j)
        {
    
    
            int dx = X1[i] - X2[j], dy = Y1[i] - Y2[j];
            T3[i][j] = sqrt(dx * dx + dy * dy) / V;
        }
    double lb = T1, ub = T1 + 49 * (T1 + T2) + 1;
    while (ub - lb > eps)
    {
    
    
        double mid = (lb + ub) / 2;
        if (judge(mid))
            ub = mid;
        else
            lb = mid;
    }
    printf("%.6f\n", ub);
    return 0;
}

Supongo que te gusta

Origin blog.csdn.net/neweryyy/article/details/115278764
Recomendado
Clasificación