第一阶段(之三)

3 views
Skip to first unread message

珠浩 杨

unread,
Nov 20, 2011, 5:43:46 AM11/20/11
to Flying
这是第三个算法了,希望我们大家都能够很好的去学习。

算法名字:最小生成树
完成时间:一周内
参与人员:杨珠浩,邱伟儒,邱志海

杨珠浩
2011年11月20日

Qzi

unread,
Nov 24, 2011, 7:22:56 AM11/24/11
to l_o_...@googlegroups.com
收到

2011/11/20 珠浩 杨 <clear...@gmail.com>



--
Your biological and technological distinctiveness will be added to our own. Resistance is futile.


Qzi

unread,
Nov 26, 2011, 2:15:24 PM11/26/11
to l_o_...@googlegroups.com
smt.7z

Qzi

unread,
Nov 26, 2011, 2:39:44 PM11/26/11
to l_o_...@googlegroups.com
Minimum spanning tree

------------------------------------------------------------------------------------------------
| System  | CentOS Linux release 6.0 (Final)
------------------------------------------------------------------------------------------------
| Cimpiler | gcc version 4.4.4 20100726 (Red Hat 4.4.4-13) (GCC)
------------------------------------------------------------------------------------------------

HDU 1233 的解题主要的逻辑:
    int n;
    while(scanf("%d", &n) && n)
    {
        int m = n*(n-1)/2;
        memset(city, -1, sizeof(city));
        for(int i=0; i<m; ++i)
            scanf("%d %d %d", &road[i].c1, &road[i].c2, &road[i].cost);
        sort(road, road+m, myCompare);
        int sum = 0, count = 0;
        for(int i=0; i<m; ++i)
        {
            if(Merge(road[i].c1, road[i].c2))
            {
                count ++;
                sum += road[i].cost;
            }
            if(count == n-1)
                break;
        }
        printf("%d\n", sum);
2011/11/27 Qzi <hotsea...@gmail.com>
smt.7z
Reply all
Reply to author
Forward
0 new messages