NTU-Exam 板


LINE

課程名稱︰資料結構與演算法 課程性質︰資工系大一必修 課程教師︰張智星 開課學院:電機資訊學院 開課系所︰資工系 考試日期(年月日)︰2017/04/25 考試時限(分鐘):上機考 80 mins 試題 : *本次考試有筆試與上機考兩部分,此為上機考 For each of the following problems, the time limit is 1 second, and the memory limit is 256MB. 1. (25 pts) Container identification: Problem description: Given an empty container, one can perform n operations, with each of them being either "add" (put an integer xi into it) or "remove" (take an integer xi out of it). Determine the type of the container based on the result of these n operations. Input format: The first line is an integer indicating n, the number of operations. Each of the following n lines contains two integers, ti and xi: ti: 1 for "add", 2 for "remove" xi: the integer for "add", or the integer returned from "remove". Output format: Please output one of the following answers: both: The container is both a stack and a queue. stack: The container is a stack, not a queue. queue: The container is a queue, not a stack. neither: The container is neither a stack nor a queue. Ranges of variables: 1 <= xi,n <= 2*10^5 Test cases: Input (p01_input01.txt): 4 1 10 2 10 1 20 2 20 Output (p01_output01.txt): both Input (p01_input02.txt): 4 1 10 1 20 2 20 2 10 Output (p01_output02.txt): stack Input (p01_input03.txt): 4 1 10 1 20 2 10 2 20 Output (p01_output03.txt): queue Input (p01_input04.txt): 4 1 10 1 20 2 30 2 40 Output (p01_output04.txt): neither 2. (25 pts) Game of Ongress: Problem description: To play the game of Ongress, you need to walk along a street of nn blocks. When you walk through block i, you earn pi points. You plan to play Ongress m times. The jth time you play Ongress, you plan to walk from block uj to vj, so you can collect points for each block you walk through, including block uj and vj. Compute how many points you will earn each time you play Ongress. Input format: The first line contains two integers, n and m. The second line contains n integers, p1,p2,…,pn Each of the following mm lines contains two integers, uj and vj. Output format: On the jth line (j=1,2,…,m), print the amount of points you earn at the jth time you play Ongress. Ranges of variables: 1 <= n,m <= 2*10^5 1 <= pi <= 10^9 1 <= ui <= vi <= n Test cases: Input (p02_input01.txt): 5 3 10 30 50 20 40 1 5 1 2 4 4 Output (p02_output01.txt): 150 40 20 3. (25 pts) Story of Untied Airline: Problem Description: Untied Airline have n employees. The salary of the ith employee is wi per month. On the first day of month j (j=1,2,…,m), one of two things could happen: If t_j=1, a new employee with salary v_j per month joined the airline. If t_j=2, all employees with salary higher than v_j per month were laid off. Assuming all empolyees received their salary on the last day of the month, compute the total amount the airline paid to its employees from month 1 to month m. Input format: Line 1 contains two integers, nn and mm. Line 2 contains nn integers, w1,w2,…,wn. Each of the following m lines contains two integers, tj and vj. Output format: Print an integer, the total amount the airline paid. Ranges of variables: 1 <= n,m,wi,ti <= 2*10^5 Test cases: Input (p03_input01.txt): 4 2 30000 40000 50000 60000 1 22000 2 35000 Output (p03_output01.txt): 254000 4. (25 pts) A tree or not: Problem Description: In a country, there are n cities connected by m roads, where road j connects city uj and vj. (Note that each pair of cities are connected by at most one road, and no road connects a city to itself.) If any two given cities can be connected by a unique path (consisting of one or several roads), then the road system is a tree. Determine if the road system is a tree or not. Input format: Line 1 contains two integers, n and m. Each of the following mm lines contains two integers, uj and vj, indicating there is a road between cities uj and vj. Output format: Print yes if the road system is a tree. Print no otherwise. Ranges of variables: 1 <= n,m <= 5*10^3 1 <= ui <= vi <= n Test cases: Input (p04_input01.txt): 3 2 1 3 2 3 Output (p04_output01.txt): yes Input (p04_input02.txt): 5 4 1 2 1 3 3 4 3 5 Output (p04_output02.txt): yes Input (p04_input03.txt): 6 6 1 2 1 3 2 4 3 4 4 5 5 6 Output (p04_output03.txt): no Input (p04_input04.txt): 6 4 1 2 2 3 4 5 5 6 Output (p04_output04.txt): no (Total score = 100) --



※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.112.16.134
※ 文章網址: https://webptt.com/m.aspx?n=bbs/NTU-Exam/M.1493117514.A.50F.html
1F:→ rod24574575 : 已收資訊系! 04/25 20:37







like.gif 您可能會有興趣的文章
icon.png[問題/行為] 貓晚上進房間會不會有憋尿問題
icon.pngRe: [閒聊] 選了錯誤的女孩成為魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一張
icon.png[心得] EMS高領長版毛衣.墨小樓MC1002
icon.png[分享] 丹龍隔熱紙GE55+33+22
icon.png[問題] 清洗洗衣機
icon.png[尋物] 窗台下的空間
icon.png[閒聊] 双極の女神1 木魔爵
icon.png[售車] 新竹 1997 march 1297cc 白色 四門
icon.png[討論] 能從照片感受到攝影者心情嗎
icon.png[狂賀] 賀賀賀賀 賀!島村卯月!總選舉NO.1
icon.png[難過] 羨慕白皮膚的女生
icon.png閱讀文章
icon.png[黑特]
icon.png[問題] SBK S1安裝於安全帽位置
icon.png[分享] 舊woo100絕版開箱!!
icon.pngRe: [無言] 關於小包衛生紙
icon.png[開箱] E5-2683V3 RX480Strix 快睿C1 簡單測試
icon.png[心得] 蒼の海賊龍 地獄 執行者16PT
icon.png[售車] 1999年Virage iO 1.8EXi
icon.png[心得] 挑戰33 LV10 獅子座pt solo
icon.png[閒聊] 手把手教你不被桶之新手主購教學
icon.png[分享] Civic Type R 量產版官方照無預警流出
icon.png[售車] Golf 4 2.0 銀色 自排
icon.png[出售] Graco提籃汽座(有底座)2000元誠可議
icon.png[問題] 請問補牙材質掉了還能再補嗎?(台中半年內
icon.png[問題] 44th 單曲 生寫竟然都給重複的啊啊!
icon.png[心得] 華南紅卡/icash 核卡
icon.png[問題] 拔牙矯正這樣正常嗎
icon.png[贈送] 老莫高業 初業 102年版
icon.png[情報] 三大行動支付 本季掀戰火
icon.png[寶寶] 博客來Amos水蠟筆5/1特價五折
icon.pngRe: [心得] 新鮮人一些面試分享
icon.png[心得] 蒼の海賊龍 地獄 麒麟25PT
icon.pngRe: [閒聊] (君の名は。雷慎入) 君名二創漫畫翻譯
icon.pngRe: [閒聊] OGN中場影片:失蹤人口局 (英文字幕)
icon.png[問題] 台灣大哥大4G訊號差
icon.png[出售] [全國]全新千尋侘草LED燈, 水草

請輸入看板名稱,例如:e-shopping 或 站內搜尋

TOP