POJ 1502 MPI Maelstrom

Source: Internet
Author: User

Topic Links:

http://poj.org/problem?id=1502

Main topic:

There is an information delivery system that contains n processors that transmit information in the same way that the processor with the first number 1 has information that he can pass to the next processor, and that the two processors that have the information can be passed down to the other two processors at the same time, and the four processors that have the information are then delivered in turn, What is the minimum time that all processors receive information?

Problem Solving Ideas:

The transmission path to draw out, see can be converted to the shortest path from 1 to other locations in the longest path, just see the topic feel no idea, but the establishment of the model after the use of Dijkstra is good!

1#include <vector>2#include <queue>3#include <cstdio>4#include <cstring>5#include <cstdlib>6#include <iostream>7#include <algorithm>8 using namespacestd;9 Ten #defineMAXN 110 One #defineINF 0x3f3f3f3f A  - intMAP[MAXN][MAXN], DIST[MAXN], N; -  the voidinit (); - voidDijkstra (); -  - intMain () + { -      while(SCANF ("%d", &n)! =EOF) +     { A         Chars[ -]; at init (); -          for(intI=1; i<=n; i++) -              for(intj=1; j<i; J + +) -             { -scanf ("%s", s); -                 if(s[0] <='9'&& s[0] >='0') in                 { -MAP[I][J] =0; to                      for(intk=0; S[K]; k++) +MAP[I][J] = map[i][j] *Ten+ S[k]-'0'; -Map[j][i] = Map[i][j];//the path is bidirectional the                 } *             } $ Dijkstra ();Panax Notoginseng         intMini =0; -          for(intI=2; i<=n; i++) theMini =Max (Mini, Dist[i]); +printf ("%d\n", mini); A     } the     return 0; + } -  $ voidInit () $ { -     intI, J; -      for(i=0; i<maxn; i++) the          for(j=0; j<maxn; J + +) -             if(i = =j)WuyiMAP[I][J] =0;//the cost of getting to itself is zero the             Else -MAP[I][J] =INF; Wu } -  About voidDijkstra () $ { -     BOOLVIS[MAXN]; -memset (Vis,false,sizeof(Vis)); -      for(intI=1; i<=n; i++) ADist[i] = map[1][i]; +  thevis[1] =true; -  $      for(intI=1; i<n; i++) the     { the         inttemp =INF, index; the          for(intj=2; j<=n; J + +) the         { -             if(!vis[j] && temp >Dist[j]) in             { theindex =J; thetemp =Dist[j]; About             } the         } the  theVis[index] =true; +  -          for(intj=2; j<=n; J + +) the             if(!Vis[j])BayiDist[j] = min (Dist[j], Dist[index] +map[index][j]); the     } the}

POJ 1502 MPI Maelstrom

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.