zoukankan      html  css  js  c++  java
  • 2070 爱情之路

    2070 爱情之路

     

     时间限制: 1 s
     空间限制: 128000 KB
     题目等级 : 钻石 Diamond
     
     
    题目描述 Description

     yh非常想念他的女朋友小y, 于是他决定前往小y所在的那块大陆。

    小y所在的大陆共有n个城市,m条双 向路,每条路连接一个或两个城市。经过一条路ei需要耗费时间ti。此外,每条 路均有一个特定标识,为’L’,’O’,’V’,’E’,中的某个字母。yh从1号城 市出发,前往位于n号城市的小y所在处。

    为了考验yh,小y规定,yh必须按照 ‘L’->’O’->’V’->’E’->’L’->’O’->’V’-> ’E’->.... 的顺序选择路,且所走的第一条路是’L’,最后一条路是 ’E’,每走完一个完整的’LOVE’算是通过一次考验

    在不违背小y要求的前提下,yh想花 费最少的时间到达小y的所在地,同在此时间内完成最多次考验。你能帮yh算出, 他最少要花多久到达城市n,完成多少次考验呢?

    输入描述 Input Description

    第一行为两个整数n,m表示有n个城 市,m条双向路。

    第2行到第m+1行,每行有3个整数x ,y,t和一个字符char,城市x,y之间有路,通过这条路花费的时间为t,这条路 的特殊标志为 char。

    输出描述 Output Description

    输出1行,两个整数表示yh到达城市 n花费的最少时间和该时间内通过的最多次考验数,如果不能到达则输出’ HOLY SHIT!’

    样例输入 Sample Input

    【样例输入1】

    4 4

    1 2 1 L

    2 1 1 O

    1 3 1 V

    3 4 1 E

    【样例输入2】

    4 4

    1 2 1 L

    2 3 1 O

    3 4 1 V

    4 1 1 E

    样例输出 Sample Output

    【样例输出1】

    4 1

    【样例输出2】

    HOLY SHIT!

    数据范围及提示 Data Size & Hint

    对于100%数据,1≤n≤1314,0≤M ≤13520

    分类标签 Tags 点此展开 

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

    题解:

    限制型最短路(我起的名字)

    设两个状态。

    L,O,V,E分别与1、2、3、4对应

    dis[i][j(1~4)]表示走到i点时的字 母为j的最短路

    注意更新时,要用“>=”。因为路径长度相同时, 考验数会增多

    AC代码:

    #include<cstdio>
    #include<cstring>
    #include<queue>
    #include<iostream>
    using namespace std;
    inline const int read(){
        register int x=0,f=1;
        register char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
        return x*f;
    }
    inline const char in(){
        for(register char ch=getchar();;ch=getchar()) if(ch>='A'&&ch<='Z') return ch;
    }
    const int N=1e4+10;
    struct ss{
        int v,w,logo,next;
    }e[N<<4];
    struct node{
        int id,logo;
        node(int id=0,int logo=0):id(id),logo(logo){}
    };
    int n,m,tot,dis[N][5],cnt[N][5],head[N];
    bool vis[N][5];
    void add(int x,int y,int z,int t){
        e[++tot].v=y;
        e[tot].w=z;
        e[tot].logo=t;
        e[tot].next=head[x];
        head[x]=tot;
    }
    void spfa(){
        memset(dis,0x3f3f3f3f,sizeof dis);
        queue<node>q;
        q.push(node(1,0));
        vis[1][0]=1;
        dis[1][0]=0;
        cnt[1][0]=0;
        while(!q.empty()){
            node h=q.front();q.pop();
            vis[h.id][h.logo]=0;
            for(int i=head[h.id];i;i=e[i].next){
                if(e[i].logo==(h.logo%4+1)&&dis[e[i].v][e[i].logo]>=dis[h.id][h.logo]+e[i].w){
                    dis[e[i].v][e[i].logo]=dis[h.id][h.logo]+e[i].w;
                    cnt[e[i].v][e[i].logo]=cnt[h.id][h.logo]+1;
                    if(!vis[e[i].v][e[i].logo]){
                        vis[e[i].v][e[i].logo]=1;
                        q.push(node(e[i].v,e[i].logo));
                    }
                }
            }
        }
        if(dis[n][4]!=0x3f3f3f3f) printf("%d %d",dis[n][4],cnt[n][4]>>2);
        else puts("HOLY SHIT!");
    }
    char c;
    int main(){
        n=read();m=read();
        for(int i=1,x,y,z,t;i<=m;i++){
            x=read();y=read();z=read();c=in();
            switch(c){
                case 'L':t=1;break;
                case 'O':t=2;break;
                case 'V':t=3;break;
                case 'E':t=4;break;
            }
            add(x,y,z,t);
            add(y,x,z,t);
        }
        spfa();
        return 0;
    }

     

     

  • 相关阅读:
    poj 2584 T-Shirt Gumbo (二分匹配)
    hdu 1757 A Simple Math Problem (乘法矩阵)
    矩阵之矩阵乘法(转载)
    poj 2239 Selecting Courses (二分匹配)
    hdu 3661 Assignments (贪心)
    hdu 1348 Wall (凸包)
    poj 2060 Taxi Cab Scheme (二分匹配)
    hdu 2202 最大三角形 (凸包)
    hdu 1577 WisKey的眼神 (数学几何)
    poj 1719 Shooting Contest (二分匹配)
  • 原文地址:https://www.cnblogs.com/shenben/p/6004547.html
Copyright © 2011-2022 走看看