zoukankan      html  css  js  c++  java
  • [POI2009]WIE-Hexer

    https://www.luogu.org/problem/show?pid=3489

    题目描述

    Byteasar has become a hexer - a conqueror of monsters.

    Currently he is to return to his hometown Byteburg. The way home, alas, leads through a land full of beasts. Fortunately the habitants, forced to fight the monsters for centuries, have mastered the art of blacksmithery - they are now capable of making special swords that are very efficient against the beasts.

    The land Byteasar wanders through is quite vast: many towns lie there, and many roads connect them.

    These roads do not cross outside the towns (mostly because some of them are underground passages).

    Byteasar has gathered all practical information about the land (all hexers like to know these things).

    He knows what kind of monsters he may come across each of the roads and how much time he needs to walk it down.

    He also knows in which villages there are blacksmiths and against what kinds of monsters the swords that they make work.

    Byteasar wants to get back to Byteburg as soon as possible.

    As a hexer he is quite ashamed that he does not know the best route, and that he has no sword on him at the moment.

    Help him find the shortest path to Byteburg such that whenever he could meet some king of monster, previously he would have a chance to get an appropriate sword to fight the beast.

    You need not worry about the number or weight of the swords - every hexer is as strong as an ox, so he can carry (virtually) unlimited number of equipment, swords in particular.

    大陆上有n个村庄,m条双向道路,p种怪物,k个铁匠,每个铁匠会居住在一个村庄里,你到了那个村庄后可以让他给你打造剑,每个铁匠打造的剑都可以对付一些特定种类的怪物,每条道路上都可能出现一些特定种类的怪物,每条道路都有一个通过所需要的时间,现在要从1走到n,初始的时候你没有剑,要求在经过一条道路的时候,对于任意一种可能出现在这条道路上的的怪物,你都有已经有至少一把剑可以对付他,求从1走到n的最短时间(打造剑不需要时间)

    输入输出格式

    输入格式:

    The first line of the standard input holds four integers: n,m,p,kn,m,p,k (1le nle 200,0le mle 3000,1le ple 13,0le kle n1n200,0m3000,1p13,0kn),separated by single spaces, that denote respectively:

    the number of towns, the number of roads connecting them,the number of different kinds of monsters and the number of blacksmiths.

    The towns are numbered from 11 to nn in such a way that nn is Byteburg's number and 11 is the number of the village which Byteasar starts in. The monster kinds are numbered from 11 to pp.

    In the following kk lines the profiles of successive blacksmiths are given,one per line. The (i+1)(i+1)-st line holds the integers w_i,q_i,r_{i,1}<r_{i,2}<...<r_{i,q_i}wi​​,qi​​,ri,1​​<ri,2​​<...<ri,qi​​​​(1le w_ile n,1le q_ile p,1le r_{i,j}le p1wi​​n,1qi​​p,1ri,j​​p),separated by single spaces, that denote respectively: the number of town in which the blacksmith lives, the number of different kinds of monsters against which his swords are efficient, and the kinds of monsters themselves (in increasing order). Note that a town may have more than one blacksmith.

    Then mm lines with roads' descriptions follow.The (k+i+1)(k+i+1)-th line holds the integersv_i,w_i,t_i,s_i,u_{i,1}<u_{i,2}<...<u_{i,s_i}vi​​,wi​​,ti​​,si​​,ui,1​​<ui,2​​<...<ui,si​​​​(1le v_i<w_ile n,1le t_ile 500,0le s_ile p,1le u_{i,j}le p1vi​​<wi​​n,1ti​​500,0si​​p,1ui,j​​p)separated by single spaces, that denote respectively: the towns that the road connects, the time needed to walk down the road (same in both directions), the number of different kinds of monsters that may appear on that road, and finally the kinds of monsters themselves (in increasing order). No two roads connect the same pair of towns.

    输出格式:

    Your programme is to print out one integer to the standard output - the minimum summary time required to reach Byteburg.

    Should reaching Byteburg be impossible, the number should be -11.

    输入输出样例

    输入样例#1:
    6 7 4 2
    2 1 2
    3 2 1 3
    1 2 2 0
    2 3 9 0
    1 4 2 1 2
    2 5 3 0
    4 5 5 2 2 3
    4 6 18 0
    5 6 3 2 1 2
    
    输出样例#1:
    24


    状压最短路
    #include<queue>
    #include<cstdio>
    #include<cstring>
    using namespace std;
    int sword[201];
    int dis[201][17000];
    bool v[201][17000];
    int front[201],to[6001],nxt[6001],sta[6001],val[6001],tot;
    struct node
    {
        int now,state;
    }cr,nt;
    queue<node>q;
    void add(int u,int v,int w,int s)
    {
        to[++tot]=v; nxt[tot]=front[u]; front[u]=tot; sta[tot]=s; val[tot]=w;
        to[++tot]=u; nxt[tot]=front[v]; front[v]=tot; sta[tot]=s; val[tot]=w;
    }
    int main()
    {
        int n,m,p,k;
        scanf("%d%d%d%d",&n,&m,&p,&k);
        int live,sum,x;
        while(k--)
        {
            scanf("%d%d",&live,&sum);
            while(sum--)
            {
                scanf("%d",&x);
                sword[live]|=1<<x-1;
            }
        }
        int u,t,w,state;
        while(m--)
        {
            scanf("%d%d%d%d",&u,&t,&w,&sum);
            state=0;
            while(sum--)
            {
                scanf("%d",&x);
                state|=1<<x-1;
            }
            add(u,t,w,state);
        }
        memset(dis,127,sizeof(dis));
        cr.now=1;
        cr.state=sword[1];
        dis[1][sword[1]]=0;
        v[1][sword[1]]=true;
        q.push(cr);
        while(!q.empty())
        {
            cr=q.front();
            q.pop();
            v[cr.now][cr.state]=false;
            for(int i=front[cr.now];i;i=nxt[i])
             if((sta[i]&cr.state)==sta[i] && dis[to[i]][sword[to[i]]|cr.state]>dis[cr.now][cr.state]+val[i])
             {
                dis[to[i]][sword[to[i]]|cr.state]=dis[cr.now][cr.state]+val[i];
                 if(!v[to[i]][sword[to[i]]|cr.state])
                 {
                     v[to[i]][sword[to[i]]|cr.state]=true;
                     nt.now=to[i]; nt.state=sword[to[i]]|cr.state;
                     q.push(nt);
                }
             }
        }
        tot=1<<p;
        int ans=dis[n][0]; 
        for(int i=1;i<tot;i++) ans=min(ans,dis[n][i]);
        if(ans>1500000) ans=-1;
        printf("%d",ans);
        return 0;
    }
  • 相关阅读:
    stenciljs 学习四 组件装饰器
    stenciljs 学习三 组件生命周期
    stenciljs 学习二 pwa 简单应用开发
    stenciljs ionic 团队开发的方便web 组件框架
    stenciljs 学习一 web 组件开发
    使用npm init快速创建web 应用
    adnanh webhook 框架 hook rule
    adnanh webhook 框架 hook 定义
    adnanh webhook 框架request values 说明
    adnanh webhook 框架execute-command 以及参数传递处理
  • 原文地址:https://www.cnblogs.com/TheRoadToTheGold/p/7398732.html
Copyright © 2011-2022 走看看