POJ 1125 Stockbroker Grapevine (Floyd最短路),pojstockbroker

來源:互聯網
上載者:User

POJ 1125 Stockbroker Grapevine (Floyd最短路),pojstockbroker

Floyd演算法計算每對頂點之間的最短路徑的問題

題目中隱含了一個條件是一個人可以同時將謠言傳遞給多個人

題目最終的要求是時間最短,那麼就要遍曆一遍求出每個點作為源點時,最長的最短路徑長是多少,再求這些值當中最小的是多少,就是題目所求

#include<bits/stdc++.h>using namespace std;int n,x,p,t;int m[120][120],dist[120][120],Max[120];void floyd(int n,int m[][120],int dist[][120]){    for(int i=1;i<=n;i++)        for(int j=1;j<=n;j++)        {            if(m[i][j]!=0)                dist[i][j]=m[i][j];            else                dist[i][j]=INT_MAX;        }    for(int k=1;k<=n;k++)        for(int i=1;i<=n;i++)            for(int j=1;j<=n;j++)            {                if(dist[i][k]!=INT_MAX&&dist[k][j]!=INT_MAX&&dist[i][k]+dist[k][j]<dist[i][j])                    dist[i][j]=dist[i][k]+dist[k][j];            }}int main(){int n;while(scanf("%d",&n)==1&&n){        memset(m,0,sizeof(m));        memset(Max,0,sizeof(Max));    for(int i=1;i<=n;i++)        {            scanf("%d",&x);            for(int j=1;j<=x;j++)            {                scanf("%d%d",&p,&t);                m[i][p]=t;            }        }        floyd(n,m,dist);        for(int i=1;i<=n;i++)            for(int j=1;j<=n;j++)            {                if(i!=j&&dist[i][j]>Max[i])                    Max[i]=dist[i][j];            }        int Min=INT_MAX,ans=0;        for(int i=1;i<=n;i++)        {            if(Max[i]<Min)            {                Min=Max[i];                ans=i;            }        }        printf("%d %d\n",ans,Min);}    return 0;}



ACM解題報告

一個POJ題目分類
主流演算法:
1.搜尋 //回溯
2.DP(動態規劃)
3.貪心
4.圖論 //Dijkstra、最小產生樹、網路流
5.數論 //解模線性方程
6.計算幾何 //凸殼、同等安置矩形的並的面積與周長
7.組合數學 //Polya 定理
8.類比
9.資料結構 //並查集、堆
10.博弈論
1、 排序
1423, 1694, 1723, 1727, 1763, 1788, 1828, 1838, 1840, 2201, 2376,
2377, 2380, 1318, 1877,1928, 1971, 1974, 1990, 2001, 2002, 2092, 2379,
1002(需要字元處理,排序用快排即可) 1007(穩定的排序) 2159(題意較難懂)
2231 2371(簡單排序) 2388(順序統計演算法) 2418(二叉排序樹)
2、 搜尋、回溯、遍曆
1022,1111,1118,1129,1190,1562,1564,1573,1655,2184 ,2225,2243,2312,2362,2378,2386,1010,1011,1018,1020,1054,1062,1256,1321,1363,1501,1650,1659,1664,1753,2078,2083,2303,2310,2329
簡單:1128, 1166, 1176, 1231, 1256, 1270, 1321, 1543, 1606, 1664,
1731, 1742, 1745, 1847,1915, 1950, 2038, 2157, 2182, 2183, 2381, 2386, 2426
不易:1024, 1054, 1117, 1167, 1708, 1746, 1775, 1878, 1903, 1966, 2046,
2197, 2349
推薦:1011, 1190, 1191, 1416, 1579, 1632, 1639, 1659, 1680, 1683, 1691,
1709, 1714, 1753,1771, 1826, 1855, 1856, 1890, 1924, 1935, 1948, 1979, 1980, 2170,2288, 2331, 2339,2340,1979(和迷宮類似),1980(對剪枝要求較高)
3、 曆法
1008 2080 (這種題要小心)
4、 枚舉
1012,1046, 1387, 1411, 2245, 2326, 2363, 2381,1054(剪枝要求較高),1650 (小數的精度問題)
5、 資料結構的典型演算法
容易:1182, 1656, 2021, 2023, 2051, 2153, 2227, 2236, 2247, 2352,
2395
不易:1145, 1177, 1195, 1227, 1661, 1834
推薦:1330, 1338, 1451, 1470, 1634, 1689, 1693, 1703, 1724, 1988, 2004,
2010, 2119, 2274
1125(弗洛伊德演算法) ,2421(圖的最小產生樹)
6、 動態規劃
1037 A decorative fence、
1050 To the Max、
1088 滑雪、
1125 Stockbroker Grapevine、
1141 Brackets Sequence、
1159 Palindrom......餘下全文>>
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.