MPI Maelstrom(East Central North America 1996)(poj1502)

来源:http://www.cnblogs.com/Peper/archive/2017/07/25/7237142.html
-Advertisement-
Play Games

MPI Maelstrom MPI Maelstrom 總時間限制: 1000ms 記憶體限制: 65536kB描述BIT has recently taken delivery of their new supercomputer, a 32 processor Apollo Odyssey dis ...


MPI Maelstrom

總時間限制: 
1000ms
 
記憶體限制: 
65536kB
描述
BIT has recently taken delivery of their new supercomputer, a 32 processor Apollo Odyssey distributed shared memory machine with a hierarchical communication subsystem. Valentine McKee's research advisor, Jack Swigert, has asked her to benchmark the new system. 
``Since the Apollo is a distributed shared memory machine, memory access and communication times are not uniform,'' Valentine told Swigert. ``Communication is fast between processors that share the same memory subsystem, but it is slower between processors that are not on the same subsystem. Communication between the Apollo and machines in our lab is slower yet.'' 

``How is Apollo's port of the Message Passing Interface (MPI) working out?'' Swigert asked. 

``Not so well,'' Valentine replied. ``To do a broadcast of a message from one processor to all the other n-1 processors, they just do a sequence of n-1 sends. That really serializes things and kills the performance.'' 

``Is there anything you can do to fix that?'' 

``Yes,'' smiled Valentine. ``There is. Once the first processor has sent the message to another, those two can then send messages to two other hosts at the same time. Then there will be four hosts that can send, and so on.'' 

``Ah, so you can do the broadcast as a binary tree!'' 

``Not really a binary tree -- there are some particular features of our network that we should exploit. The interface cards we have allow each processor to simultaneously send messages to any number of the other processors connected to it. However, the messages don't necessarily arrive at the destinations at the same time -- there is a communication cost involved. In general, we need to take into account the communication costs for each link in our network topologies and plan accordingly to minimize the total time required to do a broadcast.''
輸入
The input will describe the topology of a network connecting n processors. The first line of the input will be n, the number of processors, such that 1 <= n <= 100. 

The rest of the input defines an adjacency matrix, A. The adjacency matrix is square and of size n x n. Each of its entries will be either an integer or the character x. The value of A(i,j) indicates the expense of sending a message directly from node i to node j. A value of x for A(i,j) indicates that a message cannot be sent directly from node i to node j. 

Note that for a node to send a message to itself does not require network communication, so A(i,i) = 0 for 1 <= i <= n. Also, you may assume that the network is undirected (messages can go in either direction with equal overhead), so that A(i,j) = A(j,i). Thus only the entries on the (strictly) lower triangular portion of A will be supplied. 

The input to your program will be the lower triangular section of A. That is, the second line of input will contain one entry, A(2,1). The next line will contain two entries, A(3,1) and A(3,2), and so on.
輸出
Your program should output the minimum communication time required to broadcast a message from the first processor to all the other processors.
樣例輸入
5
50
30 5
100 20 50
10 x x 10
樣例輸出
35
來源
East Central North America 1996
題意:有N個處理器要傳信息,處理器給自己傳信息不需要時間,兩個人互相傳信息花費時間相等。問:從第一個處理器傳信息到其他所有處理器所用的最短時間。用鄰接矩陣輸入處理器傳信息的時間,如果兩台處理器不能傳信息就輸入‘x’。
思路:裸的單元最短路徑,可以用SPFA、Dijkstra。因為數據很小,N最大才是100,所以甚至可以用Floyd做。(身為蒟蒻的我只能用Floyd大暴力QAQ)
註意: 輸入有點坑,要用讀入優化或algorithm里的一種神奇函數atoi(),將字元轉為整型。
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int n,ans,i,j,k,e[1077][1077];
int read()
{
    int x=0;
    char ch=getchar();
    while(ch<'0'||ch>'9')   {if(ch=='x') return 1000000000;ch=getchar();}
    while(ch>='0'&&ch<='9') {x=x*10+ch-'0';ch=getchar();}
    return x;
}
int main()
{
    while(scanf("%d",&n)!=EOF)
    {
        memset(e,1000000000,sizeof(e));
        char s[8];
        for(i=2;i<=n;i++)
          for(j=1;j<i;j++)
            e[i][j]=e[j][i]=read();
        ans=-1;
        for(k=1;k<=n;k++)
            for(i=1;i<=n;i++)
            for(j=1;j<=n;j++)
                if(e[i][k]+e[k][j]<e[i][j])
                e[i][j]=e[i][k]+e[k][j];
        for(i=2;i<=n;i++)
          if(e[1][i]>ans)
            ans=e[1][i];
        printf("%d\n",ans);
    }
    return 0;
}

 


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 1. 正則表達式基礎 1.1. 簡單介紹 正則表達式並不是Python的一部分。正則表達式是用於處理字元串的強大工具,擁有自己獨特的語法以及一個獨立的處理引擎,效率上可能不如str自帶的方法,但功能十分強大。得益於這一點,在提供了正則表達式的語言里,正則表達式的語法都是一樣的,區別隻在於不同的編程語 ...
  • 加 Golang學習 QQ群共同學習進步成家立業工作 ^-^ 群號:96933959 結構體struct struct 用來自定義複雜數據結構,可以包含多個欄位(屬性),可以嵌套; go中的struct類型理解為類,可以定義方法,和函數定義有些許區別; struct類型是值類型。 struct定義 ...
  • VGGNet,牛津大學電腦視覺組(Visual Geometry Group)和Google DeepMind公司一起研發,深度捲積神經網路。VGGNet反覆堆疊3x3小型捲積核和2x2最大池化層,成功構築16~19層深捲積神經網路。比state-of-the-art網路結構,錯誤率幅下降,取得I ...
  • 1.什麼是包裝類? java是一種面向對象的編程語言,基本數據類型數據不能當做對象處理,為此java為每一種基本數據類型提供了一種以面向對象思想操作的載體,該載體即包裝類。 2.轉化 當包裝類與對應的基本數據類型運算時,包裝類自動轉化為基本數據類型。 3.Integer常量池 Integer類型變數 ...
  • 這裡提供在使用python進行開發中常使用到的方法技巧,如有不對歡迎批評指正。 要點:開發中類、變數特性查詢,類型就是類,斷言的使用,深淺複製判斷等 python腳本文件是使用UTF-8編碼的,所以在發現中文字元出現亂碼時應當考慮是否文本文件採用UTF-8編碼。 如果想指定不同的編碼需要在源碼文件中 ...
  • package cn.itheima.store.product.domain;import java.io.Serializable;import java.util.List;public class PageBean<T> implements Serializable{ private in ...
  • 題目:定義一個函數,輸入一個鏈表的頭結點,反轉該鏈表並輸出反轉後的鏈表的頭結點。解題思路:單向鏈表只能實現單向遍歷,改變鏈表方向就是要把當前鏈表的節點指向它的前一個節點,一旦當前鏈表指向發生了變化,就不能根據此節點獲取到它後面的節點,所以在改變方向前要保存當前節點的下一節點,防止鏈表斷開,因此需要三 ...
  • N個人坐成一個圓環(編號為1 - N),從第1個人開始報數,數到K的人出列,後面的人重新從1開始報數。問最後剩下的人的編號。 例如:N = 3,K = 2。2號先出列,然後是1號,最後剩下的是3號。 N個人坐成一個圓環(編號為1 - N),從第1個人開始報數,數到K的人出列,後面的人重新從1開始報數 ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...