精華區beta NTU-Exam 關於我們 聯絡資訊
課程名稱︰計算機程式設計 課程性質︰必修 課程教師︰李秀惠 開課系所︰資訊系 考試時間︰2005/11/22 14:00 ~ 18:00 注意事項:上機考 試題 : Problem 1 - Comments for Course and Exam (10 points) [ Description ] Please write down your comments for course and exam. Problem 2 - Electric Bill Calculation (20 points) [ Description ] In Taiwan, Taiwan Power Company adopts the following accumulated formula to calculate an electric bill for home-use. In this formula, they also separate summer use and non-summer use. ┌──────┬──────────┬──────────────┐ │ Level │ Summer use │ Non-summer use │ │ │ (6/1 ~ 9/30) │ (days exclude 6/1 ~ 9/30) │ ├──────┼──────────┼──────────────┤ │ ~ 110 │ 2.1 │ 2.1 │ ├──────┼──────────┼──────────────┤ │ 111 ~ 330 │ 2.7 │ 2.4 │ ├──────┼──────────┼──────────────┤ │ 331 ~ 500 │ 3.3 │ │ ├──────┼──────────┤ 2.7 │ │ 501 ~ │ 3.4 │ │ └──────┴──────────┴──────────────┘ For example, if your family use 330 degree a month, the cost of summer use is 110 * 2.1 + ( 330 - 110 ) * 2.7 = 825 And the corresponding cost of non-summer use is 110 * 2.1 + ( 330 - 110 ) * 2.4 = 759 You are asked to show the bills in both summer use and non-summer use. [ Sample Input ] Please input the degree of electric consumption: 330 [ Sample Output ] 330 degree: 825 (summer use), 759 (non-simmer use) Problem 3 - Matrix Algebra (20 points) [ Description ] Given a square matrix A ( m*m, 2 ≦ m ≦ 10 ), we have the following two functions to calculate matrix transpose A^T ( function matrixT ) and matrix division 1/A (function matrixD). A^T is defined by exchanging all elements aij with aji. 1/A is defined by replacing all elements aij with 1/aij. Now, you are asked to implement these two functions and write your main program by calling these two functions to compute 1/A^T. [ Sample Input 1 ] Please input the size of a square matrix: 5 Please input values for a square matrix: 1 0 2 3 4 3 1 1 2 1 1 3 1 1 1 1 1 2 3 1 4 1 2 1 3 [ Sample Output 1 ] The output matrix: undefined [ Sample Output 2 ] Please input the size of a square matrix: 5 Please input values for a square matrix: 1 1 2 3 4 3 1 1 2 1 1 3 1 1 1 1 1 2 3 1 4 1 2 1 3 [ Sample Output 2 ] The output matrix: 1.00 0.33 1.00 1.00 0.25 1.00 1.00 0.33 1.00 1.00 0.50 1.00 1.00 0.50 0.50 0.33 0.50 1.00 0.33 1.00 0.25 1.00 1.00 1.00 0.33 Problem 4 - Calling of Recursive Call (20 points) [ Description ] The diagram shown below (略) is spiral of equilateral triangles with side lengths which follow the Padovan seqence. The Padovan sequence is the sequence of integers P(n) defined by the initial values P(0) = P(1) = P(2) = 1, and recurrence relation P(n) = P(n-2) + P(n-3) where n > 2. Now, we define another series of A(n). A(n) is the times of calling P(0) when calculating P(n) recursively. Please print the recursive form of A(n) and then calculate it, given n ( 0 ≦ n ≦ 20 ). [ Sample Input ] Please input a non-negative number: 5 [ Sample Output ] The recursive form of A series is ??? A(5) = ??? Problem 5 - Find the Maximum (20 points) [ Description ] Given a sequence of integers, we can find the maximum in the sequence by using our algorithm. The algorithm recursively separates an array into two parts: left and right, finds the maximums fo two parts, and then compares and returns the larger one. You are asked to input an integer N ( 2 ≦ N ≦ 100 ) and N integers in sequence. Please write a recursive program to implement this algorithm to find the maximum in the sequence. [ Sample Input ] Please input hte number in the integer sequence: 5 Please input 5 integers: 20 60 15 78 30 [ Sample Output ] The maximum in 20 60 15 78 30 is 78 Problem 6 - Find the Cheapest Tour (20 points) [ Description ] The CSIE travel agent has a lot of tour packages. Given the travel points (TP), they want to find the cheapest tour. Here, we have the cost matrix store the travel cost between any two travel points. The cost is zero means no connection between the two travel points and more than zero if these two travel points are adjacent. Now, the CSIE travel agent provides 7 travel points. Please input the start point and the end point, and then find the corresponding cheapest tour. Cost Matix (略) [ Sample input ] Please input elements of corresponding cost matrix: 0 1000 2000 0 8000 0 2000 1000 0 0 4000 4000 0 0 2000 0 0 0 0 1000 0 0 4000 0 0 1000 1000 0 8000 4000 0 1000 0 0 0 0 0 1000 1000 0 0 0 2000 0 0 0 0 0 0 Please input the start point: 1 Please input the end point: 4 [ Sample Output ] The cheapest tour from 1 to 4 : 1 -> 3 -> 6 -> 4 The cost: 4000 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 59.115.147.39 ※ 編輯: yrclamb 來自: 59.115.147.39 (11/22 19:28)