资源说明:Solutions for Interview Street's codesprint for Sequoia companies.
HELP JONNY ========== Jonny has just learned Sorting in his algorithm classes. He wants to show his mother how good he is with algorithms, but his mother is very clever. She wants to ensure Jonny has learned the key concepts and not just the methods. She places N integers in order 1, 2, 3, ..., N. and asks Jonny to reverse this sequence, i.e convert this sequence to N, N-1, .... , 3, 2, 1. The only operation Jonny is allowed to do is to choose any 4 (not necessarily adjacent) integers and perform the following action: exchange the leftmost integer with the rightmost one and similarly swap the remaining two integers in the middle, both swaps must occur. He can perform this operation as many times he want. Jonny has a feeling that this may not always be possible for all sequences, so before starting he wants to know whether it is possible to do this task. Input Format First line of the input contains T, the number of testcases. Then follow T lines, each containing an integer N. Output Format For each of the given numbers print YES if the task is possible, otherwise NO. Sample Input 2 5 6 Sample Output YES NO Constrains 1 <= T <= 10 4 <= N <= 1,000,000 PUNCH ===== We have n punching bags in a row. Mr Lee is going to practice with them for the upcoming Boxing tournament. Each bag has a resistance level. Mr Lee can punch a bag if its resistance is greater than 0. He is an extremely hard puncher: when Mr Lee punches a bag, not only is its resistance set to 0 (ie: the bag is destroyed), but also the resistances of its immediately adjacent neighbors( one on left and other on right ) are decreased by one. If at any point of time the resistance of a bag drops to zero or less it is considered as destroyed. A punch on a bag with resistance greater than 0 has no impact on an immediate neighbour which is already destroyed. Mr Lee wants to maximize his (very expensive) workout sessions, and would like to punch on these bags as much as possible. For any set of punching bags, what is the maximum number of punches that he can perform? Input Format On the only line of input there are n characters describing the resistances of the bags from 1 to n. Ouput Format On the only line of the output print an integer describing the maximum number of punches Mr Lee can punch for that set of bags. Sample Input 11 Sample Ouput 1 Sample Input 021 Sample Output 2 Explanation In the first example there are two bags, and we can punch only one of them before destroying both. In the second example we can punch on the third bag and then on the second bag to obtain two punches. Constraints Each bag has a resistance level between 0 and 3 ( inclusive ) and the number of bags is not more than 100. ALTERNATING SEQUENCES ===================== Given a sequence of integers a[1],a[2],...,a[n], we call a sequence b[1], ..., b[m] an alternating sequence if: for every odd 1 < i <= m, we have b[i] < b[i-1], for every even 1 < i <= m, we have b[i] > b[i-1]. Given a sequence of integers a[1], ..., a[n], your program must find the length of the longest alternating subsequence. (we define a[i1], ..., a[im] to be a subsequence if 1<=i1< i2<...
本源码包内暂不包含可直接显示的源代码文件,请下载源码包。