• POJ 1201 Intervals


    传送门

    AcWing 362 区间洛谷 SP116 INTERVAL - IntervalsUVA 1723 Intervals

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <queue>
    #include <stack>
    #include <cmath>
    #include <algorithm>
    
    using namespace std;
    typedef long long ll;
    typedef pair<int, int> p;
    const double pi(acos(-1));
    const int maxn(5e4 + 10);
    const int maxm(5e5 + 10);
    bool vis[maxn];
    int ecnt, head[maxn], dis[maxn];
    
    struct edge {
        int to, wt, nxt;
    } edges[maxm];
    
    template<typename T>
    inline const T read()
    {
        T x = 0, f = 1;
        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;
    }
    
    template<typename T>
    inline void write(T x, bool ln)
    {
        if (x < 0) {
            putchar('-');
            x = -x;
        }
        if (x > 9) write(x / 10, false);
        putchar(x % 10 + '0');
        if (ln) putchar(10);
    }
    
    void addEdge(int u, int v, int w)
    {
        edges[ecnt].to = v;
        edges[ecnt].wt = w;
        edges[ecnt].nxt = head[u];
        head[u] = ecnt++;
    }
    
    void spfa()
    {
        queue<int> q;
        q.push(0);
        dis[0] = 0;
        vis[0] = true;
        while (not q.empty()) {
            int u = q.front();
            q.pop();
            vis[u] = false;
            for (int i = head[u]; compl i; i = edges[i].nxt) {
                int v = edges[i].to, w = edges[i].wt;
                if (dis[v] < dis[u] + w) {
                    dis[v] = dis[u] + w;
                    if (not vis[v]) {
                        vis[v] = true;
                        q.push(v);
                    }
                }
            }
        }
    }
    
    int main()
    {
    #ifdef ONLINE_JUDGE
    #else
        freopen("input.txt", "r", stdin);
    #endif
        memset(head, -1, sizeof head);
        memset(dis, -1, sizeof dis);
        int n = read<int>(), mx = 0;
        for (int i = 1; i <= n; ++i) {
            int a = read<int>() + 1, b = read<int>() + 1, w = read<int>();
            mx = max(mx, b);
            addEdge(a - 1, b, w);
        }
        for (int i = 1; i <= mx; ++i) {
            addEdge(i - 1, i, 0);
            addEdge(i, i - 1, -1);
        }
        spfa();
        printf("%d
    ", dis[mx]);
        return 0;
    }
    
  • 相关阅读:
    网页中添加下划线的方法汇总及优缺点
    git备注
    微信小程序封装年月日时分组件
    微信小程序底部弹窗动画
    微信小程序返回上一页的方法并传参
    微信小程序组件封装
    taro中子父传值
    taro初识一
    reactjs中使用高德地图计算两个经纬度之间的距离
    vue中使用scss
  • 原文地址:https://www.cnblogs.com/singularity2u/p/13854404.html
Copyright © 2020-2023  润新知