Shipping Routes

来源:互联网 发布:350模板和淘宝什么区别 编辑:程序博客网 时间:2024/04/30 09:08

fjnu acm 1689

Description

The Slow Boat to China Shipping company needs a program to help them quickly quote costs to prospective customers. The cost of a shipment depends on the size of the shipment and on how many shipping legs it requires. A shipping leg connects two warehouses, but since every pair of warehouses is not directly connected by a leg, it might require more than one leg to send a shipment from one warehouse to another.
A data set can represent from 1 to 30 warehouses. A two-letter code name will identify each warehouse (capital letters only). Shipping legs can exist between any two distinct warehouses. All legs are bidirectional.


The cost of a shipment is equal to the size of the shipment times the number of shipping legs required times $100.

The input to the program identifies the warehouse code names and the existence of all shipping legs. For a given shipping request, consisting of the size of the shipment, the source warehouse and the destination warehouse, the program will output the best (cheapest) cost for the shipment, if it is possible to send shipments from the requested source to the requested destination. Alternately, the program must state that the request cannot be fulfilled.

Input

The first line will contain an integer from 1 to 10 inclusive that represents the number of data sets in the input file. Each data set represents a new shipping configuration.

The first line of data in a data set will contain three integers, say M, N, and P: M is an integer from 1 to 30 inclusive representing the number of warehouses in the data set; N is an integer from 0 to M*(M-1)/2 inclusive that represents the number of legs between warehouses in the data set; P is an integer from 0 to 10 inclusive that represents the number of shipping requests for which cost information is required.

The second line of data in a data set contains M two-letter code names for the M warehouses of the data sets. Only capital letters are used. A single blank separates code names.

N lines follow the line of code names, containing shipping leg information in the format: ``XX YY", with XX and YY being the codes for two distinct warehouses in the set that have a direct link (a shipping leg) between them. There will be a single blank between the warehouse codes.

The N lines of shipping leg information are followed by P lines of shipping requests, one request per line. Each shipping request will begin with an integer between 1 and 20 inclusive that represents the size of the shipment. The shipment size will be followed by a pair of code names in the format ``AA BB", with AA and BB being the code for two distinct warehouses in the set which represent the source and destination of the requested shipment.

The input will be valid and consistent. A shipping leg will only be represented once within a data set. Data about legs will always refer to warehouses that have been identified as belonging to the data set. See the example below for clarification of the input format.

Output

The first line of output should read ``SHIPPING ROUTES OUTPUT". For each data set there should be a section of output enumerating which data set the output section represents followed by P lines of the required information. Each of the P lines should list either the cheapest cost of the respective shipment or the phrase ``NO SHIPMENT POSSIBLE". The end of the output should be noted also. Produce output consistent with the example below.

Sample Input

26 7 5AA CC QR FF DD ABAA CCCC QRDD CCAA DDAA ABDD QRAB DD5 AA AB14 DD CC1 CC DD2 AA FF13 AB QR3 0 1AA BB CC5 AA CC

Sample Output

SHIPPING ROUTES OUTPUTDATA SET 1$500$1400$100NO SHIPMENT POSSIBLE$2600DATA SET 2NO SHIPMENT POSSIBLEEND OF OUTPUT

Source

Mid-Atlantic USA 1996

#include "iostream"

using namespace std;

int map[101][101];
int n,m;


void floyd()
{
    int i,j,k;


    for(i=0;i<n;i++)
        for(j=0;j<n;j++)
            for(k=0;k<n;k++)
                if(map[j][k] > map[j][i] + map[i][k] )
                    map[j][k] = map[j][i] + map[i][k];

    return ;
}


int main ()
{
    int i,j,k,t,p;
    char a[100][31];
    char name1[31],name2[31];
    int nn,Case=1,mm;
    printf("SHIPPING ROUTES OUTPUT/n/n");
    scanf("%d",&mm);
    for(p=0;p<mm;p++)
    {
        scanf("%d%d%d",&n,&m,&nn);
        for(i=0;i<n;i++)
   for(j=0;j<n;j++)
    map[i][j]=999;

   for(i=0;i<n;i++)
    scanf("%s",a[i]);
   for(i=0;i<m;i++)
   {
    scanf("%s%s",name1,name2);
    for(j=0;j<n;j++)
     if(strcmp(a[j],name1)==0) break;
     for(k=0;k<n;k++)
      if(strcmp(a[k],name2)==0) break;

      map[j][k]=1;
      map[k][j]=1;
   }

   floyd();
   printf("DATA SET %d/n/n",Case);
   Case++;
   for(i=0;i<nn;i++)
   {
    scanf("%d%s%s",&t,name1,name2);

    for(j=0;j<n;j++)
     if(strcmp(a[j],name1)==0) break;
     for(k=0;k<n;k++)
      if(strcmp(a[k],name2)==0) break;

      if(map[j][k]==999)
       printf("NO SHIPMENT POSSIBLE/n");
      else
       printf("$%d/n",t*100*map[j][k]);
   }
   printf("/n");
    }
    printf("END OF OUTPUT/n");
    return 1;
}

 

 

 

原创粉丝点击