• C logistics


    C logistics

    Aim

    Your task is to write a program logistics.c to help a company determine the minimum number of distribution centres so that all cities are within a maximum distance from at least one distribution centre.

    Input

    源码传送门

    传送门:https://pan.baidu.com/s/15uTzP83Xxqm2qZI4a1yIXw?pwd=1111

    Cities

    Your program should start by prompting the user to input a positive number n followed by n lines, each containing the name of a city. An example is:

    ./logistics
    Enter the number of cities on the distribution network: 3
    Berlin
    Frankfurt
    Hamburg
    
    • 1
    • 2
    • 3
    • 4
    • 5

    You may assume that:
    • The input is syntactically correct.
    • Names require no more than 31 characters and will not use any spaces.
    • The names will be input in alphabetical order, with no name repeated.
    Hint: To read a single line with the name of a city you may use:

    scanf("%32s", city);   // city is a character array (= string variable)
    
    • 1

    Roads

    Next, your program should ask the user for the number of roads, m, then prompt the user to input m roads. Each road requires the name of a city (from), the name of another city (to) and the distance (in km). An example is:

    Enter the number of roads: 2
    Enter the name of a city: Hamburg
    Enter the name of a city: Frankfurt
    Enter the distance: 492
    Enter the name of a city: Berlin
    Enter the name of a city: Hamburg
    Enter the distance: 289
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    All roads are directional, that is, from the first city to the second city.
    You may assume that:
    • The input is syntactically correct: Each road will use the names of two different cities that have been input earlier, followed by a positive integer.
    • There will be no two roads with the same start and end point.
    Maximum distance
    Finally, your program should prompt the user to input the required maximum distance to a distribution centre:
    Enter the required maximum distance: 350
    Again, you may assume that the input is correct (a non-negative integer).

    Stage 1 (3 marks)

    For stage 1, you should demonstrate that you can read the input and generate a suitable data structure.
    For this stage, all test cases are guaranteed to satisfy the following conditions:
    • There is only one route that:
    o starts in the (alphabetically) first city,
    o goes through all other cities (but not necessarily in alphabetical order).
    Which means that in each scenario, if n is the number of cities, then there will be exactly n - 1 roads.
    • The required maximum distance is large enough so that the unique optimal solution is to have one distribution centre, in the first city.
    Hence, all you need to do for this stage is to

    1. output the name of the first city
    2. find and output, for each city in alphabetical order, the unique route from the first city, along with the distance.
      Here is an example to show the desired behaviour of your program for a stage 1 test:
    ./logistics
    Enter the number of cities on the distribution network: 3
    Berlin
    Frankfurt
    Hamburg
    Enter the number of roads: 2
    Enter the name of a city: Hamburg
    Enter the name of a city: Frankfurt
    Enter the distance: 492
    Enter the name of a city: Berlin
    Enter the name of a city: Hamburg
    Enter the distance: 289
    
    Enter the required maximum distance: 1000
    
    Hubs: Berlin
    Routes:
    Berlin: Berlin 0
    Frankfurt: Berlin - Hamburg - Frankfurt 781
    Hamburg: Berlin - Hamburg 289
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20

    Stage 2 (4 marks)

    For stage 2, you should extend your program for stage 1 such that it finds an optimal solution, that is, a minimal set of distribution centres (hubs) so that each city is within the maximum required distance from one of the centres.
    For this stage, all test cases are guaranteed to satisfy the following condition:
    • There is always a unique solution, i.e. a unique smallest set of distribution centres that satisfies the requirements.
    Hence, for this stage you need to:

    1. find and output an optimal solution
    2. output, for each city in alphabetical order, the best way to reach it from the closest distribution centre.
      Here is an example to show the desired behaviour and output of your program for a stage 2 test:
    ./logistics
    Enter the number of cities on the distribution network: 3
    Berlin
    Frankfurt
    Hamburg
    Enter the number of roads: 2
    Enter the name of a city: Hamburg
    Enter the name of a city: Frankfurt
    Enter the distance: 492
    Enter the name of a city: Berlin
    Enter the name of a city: Hamburg
    Enter the distance: 289
    
    Enter the required maximum distance: 350
    
    Hubs: Berlin, Frankfurt
    Routes:
    Berlin: Berlin 0
    Frankfurt: Frankfurt 0
    Hamburg: Berlin - Hamburg 289
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20

    Stage 3 (3 marks)

    For stage 3, you should extend your program for stage 2 such that:
    If there are two or more solutions with the same minimum number of distribution centres, you should output all minimal solutions, in alphabetical order of the distribution centres.
    For example, if {Berlin,Hamburg} and {Berlin,Frankfurt} are two optimal solutions, then the first solution in your output should be: Berlin, Frankfurt.
    Here is an example to show the desired behaviour and output of your program for a stage 3 test:

    ./logistics
    Enter the number of cities on the distribution network: 3
    Berlin
    Frankfurt
    Hamburg
    Enter the number of roads: 2
    Enter the name of a city: Hamburg
    Enter the name of a city: Frankfurt
    Enter the distance: 492
    Enter the name of a city: Berlin
    Enter the name of a city: Hamburg
    Enter the distance: 289
    
    Enter the required maximum distance: 500
    
    Hubs: Berlin, Frankfurt
    Routes:
    Berlin: Berlin 0
    Frankfurt: Frankfurt 0
    Hamburg: Berlin - Hamburg 289
    
    Hubs: Berlin, Hamburg
    Routes:
    Berlin: Berlin 0
    Frankfurt: Hamburg - Frankfurt 492
    Hamburg: Hamburg 0
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26

    Hint: For each solution, you only need to output one shortest route for each city. There will be no test cases in which a city is at equal distance from two distribution centres, or where there are two different shortest routes from a hub to a city.

    Complexity Analysis (1 mark)

    Your program should include a time complexity analysis for the worst-case asymptotic running time of your program, in Big-Oh notation, depending on the number n of cities.

    Hints

    If you find any of the following ADTs from the lectures useful, then you can, and indeed are encouraged to, use them with your program:
    • linked list ADT : list.h, list.c
    • stack ADT : stack.h, stack.c
    • queue ADT : queue.h, queue.c
    • priority queue ADT : PQueue.h, PQueue.c
    • graph ADT : Graph.h, Graph.c
    • weighted graph ADT : WGraph.h, WGraph.c
    You are free to modify any of the five ADTs for the purpose of the assignment (but without changing the file names). If your program is using one or more of these ADTs, you should submit both the header and implementation file, even if you have not changed them.
    Your main program file logistics.c should start with a comment: /* … */ that contains the time complexity of your program in Big-Oh notation, together with a short explanation.

    Testing

    We have created a script that can automatically test your program. To run this test you can execute the dryrun program that corresponds to this assignment. It expects to find, in the current directory, the program logistics.c and any of the admissible ADTs (Graph,WGraph,stack,queue,PQueue,list) that your program is using, even if you use them unchanged. You can use dryrun as follows:
    9024 dryrun logistics
    Please note: Passing dryrun does not guarantee that your program is correct. You should thoroughly test your program with your own test cases.

    Submit

    For this project you will need to submit a file named logistics.c and, optionally, any of the ADTs named Graph,WGraph,stack,queue,PQueue,list that your program is using, even if you have not changed them. You can either submit through WebCMS3 or use a command line. For example, if your program uses the Graph ADT and the queue ADT, then you should submit:
    give cs9024 assn logistics.c Graph.h Graph.c queue.h queue.c
    Do not forget to add the time complexity to your main source code file logistics.c.
    You can submit as many times as you like — later submissions will overwrite earlier ones. You can check that your submission has been received on WebCMS3 or by using the following command:
    9024 classrun -check assn

    Marking

    This project will be marked on functionality in the first instance, so it is very important that the output of your program be exactly correct as shown in the examples above. Submissions which score very low on the automarking will be looked at by a human and may receive a few marks, provided the code is well-structured and commented.
    Programs that generate compilation errors will receive a very low mark, no matter what other virtues they may have. In general, a program that attempts a substantial part of the job and does that part correctly will receive more marks than one attempting to do the entire job but with multiple compilation or runtime errors.
    Style considerations include:
    • Readability
    • Structured programming
    • Good commenting

    Plagiarism

    Group submissions will not be allowed. Your program must be entirely your own work. Plagiarism detection software will be used to compare all submissions pairwise (including submissions for similar projects in previous years, if applicable) and serious penalties will be applied, particularly in the case of repeat offences.
    • Do not copy ideas or code from others
    • Do not use a publicly accessible repository or allow anyone to see your code, not even after the deadline
    Please refer to the on-line sources to help you understand what plagiarism is and how it is dealt with at UNSW:
    • Academic Integrity and Plagiarism
    • UNSW Plagiarism Policy
    • UNSW Plagiarism Management Procedure

    Help

    See FAQ for some additional hints.

    Finally …

    Have fun! Michael

    Reproducing, publishing, posting, distributing or translating this assignment is an infringement of copyright and will be referred to UNSW Conduct and Integrity for action.

  • 相关阅读:
    第三章 ArcGIS Pro创建 python 脚本工具(四)
    java -jar 指定端口或配置文件启动jar
    Vue学习笔记16:自定义事件内容定义
    cloud-init 中文手册,最全手册,比官网讲得好
    Python自学笔记
    基本的五大排序算法
    音频编解码,利用FAAC来实现AAC编码
    分布式 PostgreSQL 集群(Citus)官方示例 - 实时仪表盘
    [附源码]Python计算机毕业设计Django电影推荐网站
    【C++笔试强训】第二十六天
  • 原文地址:https://blog.csdn.net/qq_35960743/article/details/127715545