-
Notifications
You must be signed in to change notification settings - Fork 0
HW1
There are two cities, A and B, on a straight road, and we want to drive from A to B. The distance between A and B is s; the capacity of the fuel tank is c; the car can run for distance d with a unit of fuel. There are N gas stations down the road, and the first gas station is in the city A. Now we start the trip with an empty fuel tank. Find the minimum number of stops we need to make at gas stations so that we can reach B from A.
- First input the number of test cases.
- For each test case,
- the first line contains 3 float numbers for s c d, and an integer for N.
- then N-1 float numbers in one line, the i-th number is the distance from i+1-th station to city A.
- For each test case,
- output an integer representing the minimum stops make at gas stations (including the one at city A) if the car can reach city B.
- output "fail" if the car cannot reach city B.
- There should be an empty line at the end of the output.
2
13 4 1 6
2 3 5 8 9
13 3 1 6
2 3 5 8 9
4
fail
There are two cities, A and B, on a straight road, and we want to drive from A to B. The distance between A and B is s; the capacity of the fuel tank is c; the car can run for distance d with a unit of fuel. There are N gas stations down the road, and the first gas station is in the city A. Now we start the trip with an empty fuel tank. The gas price at i-th gas station is p_i for a unit of fuel. Find the gas-filling strategy to minimize the cost for gas to get to B from A.
- First input the number of test cases.
- For each test case,
- the first line contains 3 float numbers for s c d, and an integer for N.
- then N-1 lines of input, each line contains 2 float numbers, the first one is the distance from the station to city A , and the second one is the gas price at the station.
- For each test case,
- output a float number representing the minimum cost if the car can reach city B.
- output "fail" if the car cannot reach city B.
- There should be an empty line at the end of the output.
3
13 4 1 6
0 4
2 2
3 3
5 4
8 2
9 1
13 3 1 6
0 4
2 2
3 3
5 4
8 2
9 1
29
fail
One of the first things you learn in calculus is how to minimize a differentiable function such as
One can ask what happens when these two minimization issues are brought together, and the following question
is an example of this. Suppose we have a connected graph
Suppose each function fe is a polynomial of degree 2:
- First input the number of test cases.
- For each test case,
- First line contain 2 numbers n, m, the number of nodes and edges.
- Then m lines, each contain 2 integers and 3 floats, representing two vertices of an edge and its
$a_e, b_e, c_e$ .
- For each test case, output 2 floats in one line, the
$t$ minimizes total cost of the MST and the minimum total cost of the MST.
1
3 3
1 2 2 1 0
2 3 1 0 0
1 3 2 -2 0
0.333333 -0.333333
Timing circuits are a crucial component of VLSI chips. Here’s a simple model of such a timing circuit. Consider a complete balanced binary tree with n leaves, where n is a power of two. Each edge e of the tree has an associated length le, which is a positive number. The distance from the root to a given leaf is the sum of the lengths of all the edges on the path from the root to the leaf.
The root generates a clock signal which is propagated along the edges to the leaves. We’ll assume that the time it takes for the signal to reach a given leaf is proportional to the distance from the root to the leaf.
Now, if all leaves do not have the same distance from the root, then the signal will not reach the leaves at the same time, and this is a big problem. We want the leaves to be completely synchronized, and all to receive the signal at the same time. To make this happen, we will have to increase the lengths of certain edges, so that all root-to-leaf paths have the same length (we’re not able to shrink edge lengths). If we achieve this, then the tree (with its new edge lengths) will be said to have zero skew. Our goal is to achieve zero skew in a way that keeps the sum of all the edge lengths as small as possible. Give an algorithm that increases the lengths of certain edges so that the resulting tree has zero skew and the total edge length is as small as possible.
- First input the number of test cases.
- For each test case,
- First line contain an integer
$n$ represent the number of leaves for the complete binary tree. - Then
$\log_2 n$ lines, the i-th line contain$2^i$ integers representing the weight from corresponding parent node to its child node.
- First line contain an integer
- For each test case, output the total weight of the zero-skew tree.
2
4
2 1
2 1 2 1
8
4 6
2 1 3 4
2 3 7 1 2 2 3 3
12
56