• kuangbin_ShortPath O (LightOJ 1074)


    这是什么鬼OJ啊都没见过害的我还交错语言CE了一发摔

    想着懒得重写了直接把上一题的dij改了改就交了 然后RE

    反应过来这题有负环 想着怎么标记负环同时不直接结束spfa

    看了别人的代码感叹了一下我还是太弱 多学习吧 =.=

    #include <iostream>
    #include <string>
    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <queue>
    #include <vector>
    #include <set>
    #include <algorithm>
    #define INF 0x3F3F3F3F
    using namespace std;
    
    int busy[210], val[210][210];
    int t, n, m, q, dist[210];
    bool cir[210];
    
    void spfa(int s)
    {
        int time[210];
        bool vis[210];
        queue<int> q;
        memset(vis, 0, sizeof vis);
        memset(time, 0, sizeof time);
        memset(dist, 0x3f, sizeof dist);
        
        dist[s] = 0;
        vis[s] = true;
        q.push(s);
        while(!q.empty()){
            int u = q.front();
            q.pop();
            vis[u] = false;
            if(cir[u]) continue;
            for(int i = 1; i <= n; i++){
                if(dist[i] > dist[u] + val[u][i]){
                    dist[i] = dist[u] + val[u][i];
                    if(!vis[i]){
                        q.push(i);
                        if(time[i]++ > n) cir[i] = true;
                    }
                }
            }
        }
    }
    
    int main()
    {
        scanf("%d", &t);
        for(int i = 1; i <= t; i++){
            memset(val, 0x3f, sizeof val);
            memset(cir, 0, sizeof cir);
            
            scanf("%d", &n);
            for(int j = 1; j <= n; j++){
                scanf("%d", &busy[j]);
            }
            
            scanf("%d", &m);
            for(int j = 1; j <= m; j++){
                int s, d;
                scanf("%d%d", &s, &d);
                val[s][d] = (int)pow(busy[d] - busy[s], 3);
            }
            
            spfa(1);
            scanf("%d", &q);
            printf("Case %d:
    ", i);
            while(q--){
                int d;
                scanf("%d", &d);
                if(cir[d] || dist[d] < 3 || dist[d] == INF) puts("?");
                else printf("%d
    ", dist[d]);
            }
        }
        return 0;
    }
  • 相关阅读:
    is running beyond physical memory limits. Current usage: 2.0 GB of 2 GB physical memory used; 2.6 GB of 40 GB virtual memory used
    saiku执行速度优化二
    saiku执行速度慢
    saiku 升级&备份&恢复
    saiku 展示优化第二步(要诀和技巧)
    saiku 无密码登陆
    saiku 展示优化
    saiku源代码安装
    结合使用saiku、mondrian workbentch建立多维查询报表
    浅析 mondrian 模式文件 Schema
  • 原文地址:https://www.cnblogs.com/quasar/p/5128929.html
Copyright © 2020-2023  润新知