1. 程式人生 > >第一週周賽題目表

第一週周賽題目表

第一題

One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed w kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem.

Pete and Billy are great fans of even numbers, that’s why they want to divide the watermelon in such a way that each of the two parts weighs even number of kilos, at the same time it is not obligatory that the parts are equal. The boys are extremely tired and want to start their meal as soon as possible, that’s why you should help them and find out, if they can divide the watermelon in the way they want. For sure, each of them should get a part of positive weight.

Input
The first (and the only) input line contains integer number w (1 ≤ w ≤ 100) — the weight of the watermelon bought by the boys.

Output
Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case.

Examples
Input
8
Output
YES
Note
For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos).

第二題

用1,2,…,n表示n個盤子,稱為1號盤,2號盤,…。號數大盤子就大。經典的漢諾塔問
題經常作為一個遞迴的經典例題存在。可能有人並不知道漢諾塔問題的典故。漢諾塔來源於
印度傳說的一個故事,上帝創造世界時作了三根金剛石柱子,在一根柱子上從下往上按大小
順序摞著64片黃金圓盤。上帝命令婆羅門把圓盤從下面開始按大小順序重新擺放在另一根柱
子上。並且規定,在小圓盤上不能放大圓盤,在三根柱子之間一回只能移動一個圓盤。我們
知道最少需要移動2^64-1次.在移動過程中發現,有的圓盤移動次數多,有的少 。 告之盤
子總數和盤號,計算該盤子的移動次數.
Input
包含多組資料,首先輸入T,表示有T組資料.每個資料一行,是盤子的數目N(1<=N<=60)和盤
號k(1<=k<=N)。
Output
對於每組資料,輸出一個數,到達目標時k號盤需要的最少移動數。
Sample Input
2
60 1
3 1
Sample Output
576460752303423488
4

第三題

用1,2,…,n表示n個盤子,稱為1號盤,2號盤,…。號數大盤子就大。經典的漢諾塔問
題經常作為一個遞迴的經典例題存在。可能有人並不知道漢諾塔問題的典故。漢諾塔來源於
印度傳說的一個故事,上帝創造世界時作了三根金剛石柱子,在一根柱子上從下往上按大小
順序摞著64片黃金圓盤。上帝命令婆羅門把圓盤從下面開始按大小順序重新擺放在另一根柱
子上。並且規定,在小圓盤上不能放大圓盤,在三根柱子之間一回只能移動一個圓盤。我們
知道最少需要移動2^64-1次.在移動過程中發現,有的圓盤移動次數多,有的少 。 告之盤
子總數和盤號,計算該盤子的移動次數.
Input
包含多組資料,首先輸入T,表示有T組資料.每個資料一行,是盤子的數目N(1<=N<=60)和盤
號k(1<=k<=N)。
Output
對於每組資料,輸出一個數,到達目標時k號盤需要的最少移動數。
Sample Input
2
60 1
3 1
Sample Output
576460752303423488
4

第四題

給定三條邊,請你判斷一下能不能組成一個三角形。
Input
輸入資料第一行包含一個數M,接下有M行,每行一個例項,包含三個正數A,B,C。其中A,B,C <1000;
Output
對於每個測試例項,如果三條邊長A,B,C能組成三角形的話,輸出YES,否則NO。
Sample Input
2
1 2 3
2 2 2
Sample Output
NO
YES

第五題

最近,WisKey迷上了手機鈴聲,但是他對音律不是很懂,所以他想著能否用計算機來隨機生成鈴聲。當WisKey寫好程式後,發現生成出來的根本不是鈴聲,而是噪聲!
之後WisKey查閱了一些樂譜發現,其實很多鈴聲是以某種規律變化的,這裡為了簡化這個難題,他以連續3個音符來判斷下個音符。
如有模式
在這裡插入圖片描述
在給定第一行樂譜的情況下,按模式將產生如下樂譜圖形:
在這裡插入圖片描述
我們用0表示白色格子,用1表示黑色格子。
對於沒有連續3個格子的邊緣(即沒有左邊格子或右邊格子),我們直接用白色格子代替缺少的那一個格子。
Input
第一行有一個整數T,代表有T組資料。
每組資料有一個整數M,表示要輸出M行樂譜。接著有8行模式串,左邊是音符模式,右邊是下一個音符。最後一行是第一行樂譜。
Output
輸出M行,表示M行樂譜。
Sample Input
1
16
111 1
110 1
101 1
100 1
011 1
010 0
001 1
000 0
0000000000000001000000000000000
Sample Output
0000000000000001000000000000000
0000000000000010100000000000000
0000000000000101010000000000000
0000000000001010101000000000000
0000000000010101010100000000000
0000000000101010101010000000000
0000000001010101010101000000000
0000000010101010101010100000000
0000000101010101010101010000000
0000001010101010101010101000000
0000010101010101010101010100000
0000101010101010101010101010000
0001010101010101010101010101000
0010101010101010101010101010100
0101010101010101010101010101010
1010101010101010101010101010101

第六題

某省調查城鎮交通狀況,得到現有城鎮道路統計表,表中列出了每條道路直接連通的城鎮。省政府“暢通工程”的目標是使全省任何兩個城鎮間都可以實現交通(但不一定有直接的道路相連,只要互相間接通過道路可達即可)。問最少還需要建設多少條道路?
Input
測試輸入包含若干測試用例。每個測試用例的第1行給出兩個正整數,分別是城鎮數目N ( < 1000 )和道路數目M;隨後的M行對應M條道路,每行給出一對正整數,分別是該條道路直接連通的兩個城鎮的編號。為簡單起見,城鎮從1到N編號。
注意:兩個城市之間可以有多條道路相通,也就是說
3 3
1 2
1 2
2 1
這種輸入也是合法的
當N為0時,輸入結束,該用例不被處理。
Output
對每個測試用例,在1行裡輸出最少還需要建設的道路數目。
Sample Input
4 2
1 3
4 3
3 3
1 2
1 3
2 3
5 2
1 2
3 5
999 0
0
Sample Output
1
0

998

第七題

著名出題人小Q每次比賽後都會寫一份《賽題分析》,包含比賽概況、每題的參考演算法以及一些統計數值。

對於一道題來說,小Q會統計最短的驗題人程式碼長度(Shortest judge solution)以及賽內參賽隊伍最短的AC程式碼長度(Shortest team solution)。

統計驗題人程式碼長度比較容易,因為驗題人最多也不會超過20個。但是統計選手程式碼長度就不容易了,因為大賽區動輒三四百支隊伍。

請寫一個程式,幫助小Q統計最短程式碼長度。
Input
第一行包含一個正整數T(1≤T≤13),表示賽題數量。

每道題第一行包含兩個整數n,m(2≤n≤20,0≤m≤500),分別表示驗題人數量以及AC了該題的隊伍數量。

第二行包含n個正整數a1,a2,…,an(50≤ai≤65536),依次表示每個驗題人的程式碼位元組數。

第三行包含m個正整數b1,b2,…,bn(50≤bi≤65536),依次表示每支AC隊伍的程式碼位元組數。若m=0則該行為空行。
Output
對於第i(1≤i≤T)道題,輸出三行,第一行輸出Problem x:,其中x=i+1000。

第二行輸出Shortest judge solution: y bytes.,其中y表示最短的驗題人程式碼位元組數。

第三行輸出Shortest team solution: z bytes.,其中z表示最短的選手程式碼位元組數,若不存在請輸出N/A。

注意:間隔都是一個空格。
Sample Input
2
3 2
3627 1460 5288
2365 2671
2 0
5510 7682
Sample Output
Problem 1001:
Shortest judge solution: 1460 bytes.
Shortest team solution: 2365 bytes.
Problem 1002:
Shortest judge solution: 5510 bytes.
Shortest team solution: N/A bytes.

第八題

Someday, Drazil wanted to go on date with Varda. Drazil and Varda live on Cartesian plane. Drazil’s home is located in point (0, 0) and Varda’s home is located in point (a, b). In each step, he can move in a unit distance in horizontal or vertical direction. In other words, from position (x, y) he can go to positions (x + 1, y), (x - 1, y), (x, y + 1) or (x, y - 1).

Unfortunately, Drazil doesn’t have sense of direction. So he randomly chooses the direction he will go to in each step. He may accidentally return back to his house during his travel. Drazil may even not notice that he has arrived to (a, b) and continue travelling.

Luckily, Drazil arrived to the position (a, b) successfully. Drazil said to Varda: “It took me exactly s steps to travel from my house to yours”. But Varda is confused about his words, she is not sure that it is possible to get from (0, 0) to (a, b) in exactly s steps. Can you find out if it is possible for Varda?

Input
You are given three integers a, b, and s ( - 109 ≤ a, b ≤ 109, 1 ≤ s ≤ 2·109) in a single line.

Output
If you think Drazil made a mistake and it is impossible to take exactly s steps and get from his home to Varda’s home, print “No” (without quotes).

Otherwise, print “Yes”.

Examples
Input
5 5 11
Output
No
Input
10 15 25
Output
Yes
Input
0 5 1
Output
No
Input
0 0 2
Output
Yes
Note
In fourth sample case one possible route is: .

第九題

統計每個母音字母在字串中出現的次數。
Input
輸入資料首先包括一個整數n,表示測試例項的個數,然後是n行長度不超過100的字串。
Output
對於每個測試例項輸出5行,格式如下:
a:num1
e:num2
i:num3
o:num4
u:num5
多個測試例項之間由一個空行隔開。

請特別注意:最後一塊輸出後面沒有空行:)
Sample Input
2
aeiou
my name is ignatius
Sample Output
a:1
e:1
i:1
o:1
u:1

a:2
e:1
i:3
o:0
u:1

第十題

給定一個日期,輸出這個日期是該年的第幾天。
Input
輸入資料有多組,每組佔一行,資料格式為YYYY/MM/DD組成,具體參見sample input ,另外,可以向你確保所有的輸入資料是合法的。
Output
對於每組輸入資料,輸出一行,表示該日期是該年的第幾天。
Sample Input
1985/1/20
2006/3/12
Sample Output
20
71