zoukankan      html  css  js  c++  java
  • 古老的四种图存储方式

    #include <iostream>

    #include <cstdio>

    #include <cstring>

    #include <cstdlib>

    #include <cmath>

    using namespace std;

    int graph[100][100];

    int n,m;

    int x,y,w;

    int main()

    {

        scanf("%d%d",&n,&m);

        for(int i = 1;i <= n;i ++)

          for(int j = 1;j <= n;j ++)

          {

              if(i == j)

                 graph[i][j] = 0;

              else

                 graph[i][j] = 1000000;

          }

        while(m --)

        {

            scanf("%d%d%d",&x,&y,&w);

            graph[x][y] = w;

        }

        for(int i = 1;i <= n;i ++)

           for(int j = 1;j <= n;j ++)

              if(graph[i][j] != 0 && graph[i][j] != 1000000)

                 printf("%d -> %d have %d longth ",i,j,graph[i][j]);

    #include <iostream>

    #include <cstdio>

    #include <cstring>

    #include <cstdlib>

    #include <cmath>

    #include <algorithm>

    using namespace std;

    struct Node

    {

        int from;

        int to;

        int w;

    };

    Node edge[10000];

    int head[10000];

    int n,m;

    int x,y,w;

    bool cmp(Node a,Node b)

    {

        if(a.from == b.from && a.to == b.to)

            return a.w < b.w;

        if(a.from == b.from)

            return a.to < b.to;

        return a.from < b.from;

    }

    int main()

    {

        scanf("%d%d",&n,&m);

        for(int i = 1;i <= m;i ++)

        {

            scanf("%d%d%d",&edge[i].from,&edge[i].to,&edge[i].w);

        }

        sort(edge + 1,edge + m,cmp);

        memset(head,-1,sizeof(head));

        head[edge[0].from] = 0;

        for(int i = 1;i < m;i ++)

        if(edge[i].from != edge[i - 1].from)

            head[edge[i].from] = i;

        for(int i = 1;i <= n;i ++)

        {

           for(int k = head[i];edge[k].from == i && k < m;k ++)

               printf("%d -> %d %d ",edge[k].from,edge[k].to,edge[k].w);

        }

    }}

    #include <iostream>

    #include <cstdio>

    #include <cstring>

    #include <cstdlib>

    #include <cmath>

    #include <algorithm>

    using namespace std;

    struct EdgeNode

    {

        int to;

        int w;

        EdgeNode * next;

    };

    struct VNode

    {

        int from;

        EdgeNode * first;

    };

    VNode Adjlist[1000];

    int n,m;

    int x,y,w;

    int main()

    {

        scanf("%d%d%d",&n,&m);

        while(m --)

        {

            scanf("%d%d%d",&x,&y,&w);

            EdgeNode *p = new EdgeNode();

            p -> to = y;

            p -> w = w;

            p -> next = Adjlist[x].first;

            Adjlist[x].first = p;

        }

        for(int i = 1;i <= n;i ++)

        {

            for(EdgeNode * k;k != NULL;k = k -> next)

            printf("%d %d have %d ",i,k -> to,k -> w);

        }

    #include <iostream>

    #include <cstdio>

    #include <cstring>

    #include <cstdlib>

    #include <cmath>

    #include <algorithm>

    using namespace std;

    int head[10000];

    struct EdgeNode

    {

        int to;

        int w;

        int next;

    };

    EdgeNode Edges[10000];

    int n,m;

    int x,y,w;

    int main()

    {

        scanf("%d%d",&n,&m);

        memset(head,-1,sizeof(head));

        for(int k = 1;k <= m;k ++)

        {

            scanf("%d%d%d",&x,&y,&w);

            Edges[k].to = y;

            Edges[k].w = w;

            Edges[k].next = head[x];

            head[x] = k;

        }

        for(int i = 1;i <= n;i ++)

          for(int k = head[i];k != -1;k = Edges[k].next)

              printf("%d %d have %d ",i,Edges[k].to,Edges[k].w);

    }}

  • 相关阅读:
    python_django_sae入口配置
    Python_问题收录总结
    python_不用循环打印1-1000
    python_程序模拟浏览器请求及会话保持
    python_socket
    【SIGGRAPH】【最终幻想XV】的战斗场景实时演示的要点解说
    【SIGGRAPH】最终幻想15的渲染技术
    【SIGGRAPH】用【有说服力的照片真实】技术实现最终幻想15的视觉特效
    罪恶装备 Xrd REVELATOR 3D进化出的非照片真实视觉
    《最终幻想XV》中角色AI的意识决策系统解析
  • 原文地址:https://www.cnblogs.com/GODLIKEING/p/3329937.html
Copyright © 2011-2022 走看看