HDU 3498 whosyourdaddy 重复覆盖 DLX+A*

在《魔兽争霸》的世界中,七零决定利用‘谁是你的爸爸’技能来扭转战局,通过深入理解深渊领主的Cleaving Attack技能,计算最少攻击次数以消灭所有敌方单位。本文探讨了如何运用链表结构解决这一问题,并提供了一个高效的算法实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

whosyourdaddy

Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1495    Accepted Submission(s): 749


Problem Description
sevenzero liked Warcraft very much, but he haven't practiced it for several years after being addicted to algorithms. Now, though he is playing with computer, he nearly losed and only his hero Pit Lord left. sevenzero is angry, he decided to cheat to turn defeat into victory. So he entered "whosyourdaddy", that let Pit Lord kill any hostile unit he damages immediately. As all Warcrafters know, Pit Lord masters a skill called Cleaving Attack and he can damage neighbour units of the unit he attacks. Pit Lord can choice a position to attack to avoid killing partial neighbour units sevenzero don't want to kill. Because sevenzero wants to win as soon as possible, he needs to know the minimum attack times to eliminate all the enemys.
 

Input
There are several cases. For each case, first line contains two integer N (2 ≤ N ≤ 55) and M (0 ≤ M ≤ N*N),and N is the number of hostile units. Hostile units are numbered from 1 to N. For the subsequent M lines, each line contains two integers A and B, that means A and B are neighbor. Each unit has no more than 4 neighbor units. The input is terminated by EOF.
 

Output
One line shows the minimum attack times for each case.
 

Sample Input
  
5 4 1 2 1 3 2 4 4 5 6 4 1 2 1 3 1 4 4 5
 

Sample Output
  
2 3
 

Author
sevenzero
 

Source


深渊领主有一个技能,溅射(顺势斩 Cleaving Attack),当它把一个单位杀死的时候与该其直接相连的所有单位都要被杀死。

求最少攻击单位数。

并不记得深渊领主有溅射啊..再一看原来不是Dota..是War3啊...呵呵

双十字链表美如画w


/** Author: ☆·aosaki(*’(OO)’*)  niconiconi★ **/
//#pragma comment(linker, "/STACK:1024000000,1024000000")
//#include<bits/stdc++.h>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <list>
#include <stack>
//#include <tuple>
#define ALL(v) (v).begin(),(v).end()
#define foreach(i,v) for (__typeof((v).begin())i=(v).begin();i!=(v).end();i++)
#define SIZE(v) ((int)(v).size())
#define mem(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
#define lp(k,a) for(int k=1;k<=a;k++)
#define lp0(k,a) for(int k=0;k<a;k++)
#define lpn(k,n,a) for(int k=n;k<=a;k++)
#define lpd(k,n,a) for(int k=n;k>=a;k--)
#define sc(a) scanf("%d",&a)
#define sc2(a,b) scanf("%d %d",&a,&b)
#define lowbit(x) (x&(-x))
#define pi pair<int,int>
#define vi vector<int>
#define PI acos(-1.0)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define TT cout<<"*****"<<endl;
#define TTT cout<<"********"<<endl;
inline int gcd(int a,int b)
{
    return a==0?b:gcd(b%a,a);
}

#define INF 1e6
#define eps 1e-8
#define mod 10007
#define MAX 10010
#define maxn 60
#define maxm 360

using namespace std;

int n,m,th,ans;
int U[maxm],R[maxm],D[maxm],L[maxm];
int s[maxn];
int in[maxm];
bool pos[maxn][maxn];

void init()
{
    mem(U);
    mem(D);
    mem(L);
    mem(R);
    mem(s);
    mem(pos);
    th=0;
    ans=INF;
}

int link(int ll, int rr, int uu, int dd)
{
    th++;
    L[th] = ll;
    R[th] = rr;
    U[th] = uu;
    D[th] = dd;
    L[rr] = R[ll] = D[uu] = U[dd] = th;
    return th;
}

void remove(int x)
{
    for (int i = D[x]; i != x; i = D[i])R[L[i]] = R[i], L[R[i]] = L[i];
}

void restore(int x)
{
    for (int i = D[x]; i != x; i = D[i])R[L[i]] = i, L[R[i]] = i;
}

void input()
{
    int b,c;
    while(m--)
    {
        sc2(b,c);
        pos[b][c]=1;
        pos[c][b]=1;
    }
    lp(i,n) pos[i][i]=1;
    lp(i,n) link(i-1,0,th+1,th+1);
    lp(i,n)
    {
        int last=0;
        lp(j,n)
            if(pos[i][j])
            {
                s[j]++;
                if (last)
                    last=link(last,R[last],U[j],j);
                else last=link(th+1,th+1,U[j],j);
                in[th]=j;
            }
    }
}

int H()
{
    int re=0;
    bool vis[maxn]={0};
    for (int x=R[0];x;x=R[x])
        if (!vis[x])
        {
            re++;
            for (int i=D[x];i!=x;i=D[i])
                for (int j=R[i];j!=i;j=R[j])
                    vis[in[j]]=1;
        }
    return re;
}

void dance(int step)
{
    if(!R[0])
    {
        ans=min(ans,step);
        return;
    }
    if (step+H()>=ans)return;
    //printf("%d\n", step);
    int mm=INF,x;
    for (int i=R[0];i;i=R[i])
        if (s[i]<mm)
        {
           mm=s[i];
           x=i;
        }
    for (int i=D[x];i!=x;i=D[i])
    {
        remove(i);
        for(int j=R[i];j!=i;j=R[j])
          remove(j);
        dance(step+1);
        for (int j=R[i];j!=i;j=R[j])
          restore(j);
        restore(i);
    }
}

int main()
{
    //freopen("in.txt","r",stdin);
    while (~sc2(n,m))
    {
        init();
        input();
        dance(0);
        printf("%d\n",ans);
    }
    return 0;
}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值