zoukankan      html  css  js  c++  java
  • codeforce Gym 100342H Hard Test (思考题)

    题意:构造让Dijkstra单源最短路算法有效松弛次数最多的数据。。。

    题解:构造,题意换种说法就是更新晚的路径要比更新早的路径短。因为所有点都会更新一次,那么按照更新时间形成一条链,即到最后一个点的最短路径,

    注意:越在这条链的后面的边越晚更新,然后添加边,在前面的点所连的边一定是先更新的,所以反过来添加边的时候只要保证比之前的路径更长就行了。

    #include<bits/stdc++.h>
    using namespace std;
    
    typedef long long ll;
    #define fi first
    #define se second
    #define bug(x) cout<<#x<<'='<<x<<endl;
    #define FOR(i,s,e) for(int i = s; i < e; i++)
    
    const int maxn = 1005;
    
    int G[maxn][maxn];
    
    #define local
    int main()
    {
    #ifdef local
        freopen("test.in","r",stdin);
        freopen("test.out","w",stdout);
    #endif // local
        //memset(G,-1,sizeof(G));
        int n,m; scanf("%d%d",&n,&m);for(int i = 1; i < n; i ++) {
            printf("%d %d 0
    ",i,i+1);
        }
        m -= n-1;
        for(int i = n-2; i > 0 && m; i--){
            for(int j = i+2; j <= n && m; j++){
                m--;
                G[i][j] = G[i][i+1] + G[i+1][j];
                printf("%d %d %d
    ",i,j,++G[i][j]);
            }
        }
        return 0;
    }
  • 相关阅读:
    ARP:地址解析协议,RARP
    pip 安装psutil 报错 error: command 'gcc' failed with exit status 1
    linux shell 控制脚本
    linux shell 呈现数据
    linux shell 处理用户输入
    shell结构化命令
    centos7 安装配置 squid作为正向代理
    linux基本脚本
    linux文件权限
    模拟垃圾分布
  • 原文地址:https://www.cnblogs.com/jerryRey/p/4708905.html
Copyright © 2011-2022 走看看