1522 - I2P (I) 2018_Chen_Lab2 Scoreboard

Time

2018/10/11 13:20:00 2018/10/11 15:20:00

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

# Problem Pass Rate (passed user / total user)
12026 lab02_a
12027 lab02_b

12026 - lab02_a   

Description

The input contains nine different numbers, which are 1 to 9 in some random order, for example, 4 1 5 9 8 7 3 6 2. Now, start from the first place, we get the number 4. It indicates that the next number we need to pick is at the 4th place, which is 9. Likewise, we then go the 9th place and get the number 2. We repeat this process until we go to a place that has already been visited. In this example, we will stop at the second place and get the number 1, because we have found a circle. Therefore, along the way we pick four numbers, 4 9 2 1, and the output is the sum of these numbers, which is 16.
Note that we always start from the first place.
Other examples: Consider the input 2 3 4 5 6 7 8 9 1, the output should be 45 since we will visit the numbers one by one and go back to the beginning. Consider the input 1 9 8 7 6 5 4 3 2, the output should be 1 since we stop immediately and cannot go anywhere. Consider the input 9 2 3 4 5 6 7 8 1, the output should be 10.
 

Input

A random sequence of the nine different numbers of 1 to 9.

Output

The sum of the numbers being visited. Remember to print a '\n' at the end of the sum.

Sample Input  Download

Sample Output  Download

Tags




Discuss




12027 - lab02_b   

Description

Bob is a businessman. He always stays at city A or city  B.

Assume Bob stays at city A today , and we can use a transition matrix P to infer the probability of at which city will Bob stays tomorrow.

e.g.
Let  VnT = [ va , vb ]

Vn is a 2 by 1 column vector.
va denotes the probability that Bob stays at city A on n-th day,
vb denotes the probability that Bob stay at city B on n-th day.

After 1 day, the probability should be represented as Vn+1 , where Vn+1 = Vn * P.

P is a 2 by 2 square matrix, representing the transition probability:

P = ┌ p1  p2 ┐
       └ p3  p4 ┘


As time passes, the probability of Bob staying at city A will decrease.

After n days, the probability of Bob staying at city A will smaller than or equal to a target value T.

The question is :

Suppose that Bob stays at city A today ( va = 1 , vb = 0)
How many days do we need to make va smaller than or equal to the target value T ?
Namely , n = ?

Note :

The test case will make va monotonically decrease .

助教出的測資一定會讓 va 隨著時間增加而逐漸遞減

 

Input

There are multiple testcases in the input.

The first line contains a integer N, indicating the number of testcases.

You can use this format in your code:

int i , N;

scanf("%d",&N);

for(i=0;i<N;i++){

      // your code to deal with each testcase

}

The following lines are testcases.

For each testcase, there are 5 floating points in a line.

The 1st ~ 4th floating points (p1, p2, p3, p4) are the elements in trasition matrix P.

The 5th floating point is the target value T.

Output

For each testcase.

Output integer n that tell us how many days should we take to reach the target probability.

And add a '\n' at the end of each output.

 

Sample Input  Download

Sample Output  Download

Tags




Discuss