723 - 103學年 資料結構導論HW 1 Scoreboard

Time

2015/04/06 19:00:00 2015/04/24 23:59:59

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

# Problem Pass Rate (passed user / total user)
10502 Joseph Problem
10507 Postfix notation
10511 queue

10502 - Joseph Problem   

Description

大家還記得Joseph問題嗎?
在原始的遊戲裡有N個人,編號1~N。
所有人按編號1~N順時針圍成一個圓圈,一開始編號1的人拿刀。
每個編號的人一旦拿到刀,就會殺掉他順時針方下的下一個人,並且把刀再傳給下一個人。
請問要在哪一個編號才能活到最後呢?

現在我們來做個小小的變形,我們每次要殺的人改成跨k個人,那最後活著的人會是編號幾呢?
(原始問題裡是跨0個人,因為就殺下一個)
並把刀交給被殺的人的下一個!

假設一開始有10個人,k=3
則一開始編號1拿到刀,跨過3個人(編號2,3,4),所以會殺掉編號5的人,並把刀交給編號6~

假設一開始有2個人,k=1

則編號1跨過編號2後,就自殺了!!

因此最後活得會是編號2喔: D
 

Input

輸入有多筆測資!請使用循環輸入喔!

每筆測資一行,有兩個數字N和k
用一個空白隔開
2<=N<=1000
0<=k

Output

每筆測資輸出一行,輸出編號幾的人可以活到最後。
 

Sample Input  Download

Sample Output  Download

Tags




Discuss




10507 - Postfix notation   

Description

Postfix notation is a kind of expression for mathematic widely used in computer architectures. The meaning of postfix notation is fairly simple and can be concluded as follow:
(1) There are two kinds of token: operators (e.g. “+”, “-“, ”*”, “/”) and operands (values, in other word).
(2) The operators follow their operands. For example, “3 + 4” (infix notation) will be written into “3 4 +”.
(3) If there are multiple operations, the operator is given immediately after its second operand. For example, “3 – 4 + 5” will be written into “3 4 – 5 +”.

Input

The first line of the input contains an integer N (N ≤ 1000) which denotes the number of test cases. Each test case begins with an integer M (M ≤ 10000) representing the number of tokens in the expression, followed by M tokens in the next line. Tokens are separated by spaces and the operators contain only “+”, “-”; the operands are integers in the range [0, 100]. Calculate the result of the expression. You may assume that the given expressions are always valid.

Output

The output of each test case occupies a line. Each line begins with the test case number “Case i:”, and then a space character followed by the evaluated answer.

Sample Input  Download

Sample Output  Download

Tags




Discuss




10511 - queue   

Description

n個人在排隊買午餐,餐廳突然宣布晚半個小時開,等待實在太浪費時間了,於是大家休息去做自己的事半個小時再回來,於是大家一人拿一張字卡,寫下前面人的學號,跟後面人的學號,如果前面或後面沒人就寫0,半個小時回來後大家發現,要還原原本的隊列不是那麼容易,於是請你寫個程式幫大家

source:http://codeforces.com/contest/490/problem/B

Input

多筆測資請用EOF結束
每筆測資第一行n,之後n行兩個整數分別為前面人的學號和後面人的學號
2<=n<=10^5
1<=學號<=10^6 且每個人學號不重複

Output

每筆測資請輸出一行n個數字,代表原隊列的順序(學號)學號間用一個空白隔開

Sample Input  Download

Sample Output  Download

Tags




Discuss