CPMSC465 Archives - Mantutor https://mantutor.com/product-category/cpmsc465/feed/ Programming Help · Debugging · Full-Stack Learning Thu, 30 Sep 2021 01:39:49 +0000 en-US hourly 1 https://i0.wp.com/mantutor.com/wp-content/uploads/2022/02/cropped-mantutor2.png?fit=32%2C32&ssl=1 CPMSC465 Archives - Mantutor https://mantutor.com/product-category/cpmsc465/feed/ 32 32 182416984 CPMSC465-Assignment 5 Part 1 Knapsck https://mantutor.com/product/cpmsc465-assignment-5-part-1-knapsck-solved/ Thu, 30 Sep 2021 01:34:48 +0000 https://mantutor.com/?post_type=product&p=66798 Given n jobs, job i starts from S_i, finishes at T_i, and has the weight V_i. Two jobs are compatible if they don’t overlap. Design an algorithm to find maximum weight subset of mutually compatible jobs. (Job i and job j are compatible if T_i == S_j) # Input There are n + 1 lines, […]

The post CPMSC465-Assignment 5 Part 1 Knapsck appeared first on Mantutor.

]]>
Given n jobs, job i starts from S_i, finishes at T_i, and has the weight V_i. Two jobs are compatible if they don’t overlap. Design an algorithm to find maximum weight subset of mutually compatible jobs. (Job i and job j are compatible if T_i == S_j)

# Input

There are n + 1 lines, the first line gives only one number `n`, the number of jobs. Each of the following lines gives three intergers S_i, T_i, V_i separated by space.

1 <= S_i < T_i <= 10000

1 <= V_i <= 10000

1 <= n <= 1000

Your code should read the input from standard input (e.g.
using functions `input()/raw_input()` in Python and `cin/scanf` in C++).

# Output

One number in a line, the total weight of the maximum weight compatible job subset.

Your code should write the output to standard output (e.g. using functions `print` in Python and `cout/printf` in C++).

The post CPMSC465-Assignment 5 Part 1 Knapsck appeared first on Mantutor.

]]>
66798
CMPSC465-Assignment 4 Part 1 Find Negative Cycle https://mantutor.com/product/cmpsc465-assignment-4-part-1-find-negative-cycle-solved/ Thu, 30 Sep 2021 01:30:28 +0000 https://mantutor.com/?post_type=product&p=66790 Given a directed graph G = (V,E) with edge length l(e) and a source vertex s. Find out if there is a negative cycle in G. A negative cycle in a graph is a cycle with negative length. # Input The graph has `n` vertices and `m` edges. There are m + 1 lines, the […]

The post CMPSC465-Assignment 4 Part 1 Find Negative Cycle appeared first on Mantutor.

]]>
Given a directed graph G = (V,E) with edge length l(e) and a source vertex s. Find out if there is a negative cycle in G. A negative cycle in a graph is a cycle with negative length.

# Input

The graph has `n` vertices and `m` edges.
There are m + 1 lines, the first line gives three numbers `n`,`m` and `s`(1 <= s <=n), describing the number of vertices, the number of edges and the source vertex. Each of the following lines contains three integers `a`, `b` and `c`, meaning there is an edge (a,b) belong to E and the length of the edge is c. All the numbers in a line are separated by space. (`1 <= a,b <= n`)

1 <= `n` <= 1000, 1 <= `m` <= 5000, and the length of `edge` is in the range of [-1000, 1000]. You can assume that all the vertices are reachable from `s`.

Your code should read the input from standard input (e.g.
using functions `input()/raw_input()` in Python and `cin/scanf` in C++).

# Output

One line, if there is a negative cycle, output should be ‘True’. If not, output should be ‘False’.

Your code should write the output to standard output (e.g. using functions `print` in Python and `cout/printf` in C++).

The post CMPSC465-Assignment 4 Part 1 Find Negative Cycle appeared first on Mantutor.

]]>
66790
CPMSC465-Assignment 2 Part 2 Upper and Lower https://mantutor.com/product/cmpsc465-assignment-2-part-2-upper-and-lower-solved/ Thu, 30 Sep 2021 01:26:33 +0000 https://mantutor.com/?post_type=product&p=66791 Given a set of lines, each line is represented as `y = a * x + b`. Calculate the number of lines in the upper-envelop and the number lines in the lower-envelop.  (You may assume that there is no three lines going through the same point. And for any three lines, they can’t be in […]

The post CPMSC465-Assignment 2 Part 2 Upper and Lower appeared first on Mantutor.

]]>
Given a set of lines, each line is represented as `y = a * x + b`. Calculate
the number of lines in the upper-envelop and the number lines in the
lower-envelop.  (You may assume that there is no three lines going through the
same point. And for any three lines, they can’t be in all parallel to each
other, but it’s possible that two lines are parallel to each other.)

# Input

There are n + 1 lines, the first line gives only one number `n`, the number of lines. Each of the following lines contains two floating numbers `a` and `b` separated by space which represent a line as `y = a * x + b`.

You can assume that 0 <= n <= 1000, and that each floating numbers
are in the range of [-100.0, 100.0].

Your code should read the input from standard input (e.g.
using functions `input()/raw_input()` in Python and `cin/scanf` in C++).

# Output

Two numbers in a line separated by space, the number of lines in the upper-envelop and the number lines in the lower-envelop.

Your code should write the output to standard output (e.g. using functions `print` in Python and `cout/printf` in C++).

# Requirement

Your algorithm should run in O(nlogn) time.

Time limtation: 5 seconds.

Memory limitation: 1.0 GB

The post CPMSC465-Assignment 2 Part 2 Upper and Lower appeared first on Mantutor.

]]>
66791
CPMSC465-Assignment 1 Part 2 Implement Merge-Sort to Sort an Array https://mantutor.com/product/cpmsc465-assignment-1-part-2-implement-merge-sort-to-sort-an-array-solved/ Thu, 30 Sep 2021 01:22:06 +0000 https://mantutor.com/?post_type=product&p=66788 # Input Two lines, the first line gives only one number `n`, the number of integers in the array. And the second line gives `n` numbers which are the `n` integers in the array. All numbers are separated by space. You can assume that 0 <= n <= 10000, and that each number in the […]

The post CPMSC465-Assignment 1 Part 2 Implement Merge-Sort to Sort an Array appeared first on Mantutor.

]]>
# Input

Two lines, the first line gives only one number `n`, the number of integers in the array. And the second line gives `n` numbers which are
the `n` integers in the array. All numbers are separated by space.

You can assume that 0 <= n <= 10000, and that each number in the arrarys
are in the range of [-2147483648, 2147483647].

Your code should read the input from standard input (e.g. using functions `input()/raw_input()` in Python and `cin/scanf` in C++).

# Output

One line, describing the sorted array, in ascending order.
There should be `n` integers in a line give all numbers in the sorted array (in ascending order).
All numbers should be separated with space.
(You don’t need to output the size of the array `n`.)

Your code should write the output to standard output (e.g. using functions `print` in Python and `cout/printf` in C++).

# Requirement

Your algorithm should run in O(nlogn) time. You are not allowed to call any in-built sort function.

Time limtation: 5 seconds.

Memory limitation: 1.0 GB.

# Environment

Your code will be running on Ubuntu 18.04.5.

Now only accept C++ and Python2/Python3 code, g++ version 7.5.0 and Python versions are Python 2.7.17 and Python 3.6.9.

# Examples and Testing

Some examples (e.g., input-x.txt and output-x.txt, x = 1, 2) are provided.
For Python code, try the following to test your code
“`
python ./solution.py < input-x.txt > my-output-x.txt
“`
For C++ code, try the following to test your code
“`
g++ -o mybinary solution.cpp
./mybinary < input-x.txt > my-output-x.txt
“`

Your output `my-output-x.txt` needs to be *match exactly* to the given `output-x.txt`.
On Unix-based systems you can use `diff` to compare them:
“`
diff my-output-x.txt output-x.txt
“`
On Windows you can use `fc` to compare them:
“`
fc my-output-x.txt output-x.txt
“`

The post CPMSC465-Assignment 1 Part 2 Implement Merge-Sort to Sort an Array appeared first on Mantutor.

]]>
66788