Amazon Campus(2013-Sep-25)

Question 1 / 2 (Amazon Campus(4): Buy smallest number of goods using all the money)

There are m different goods, each with different price and unlimited units. You have n dollars in your hand, and you’d like to spend all the money (that is, n dollars) with the goal that the smallest number of goods is bought. Please find out one such solution. If there is no solution, please print “0”. You just need to consider the case that price and money are positive integers that are all in the range [1, 2^31 - 2).

Input:

m --- number of different goods

m different prices (separated by ' ')

money (that is, n dollars)

Output:

The number of bought goods (in the same order as input good, separated by ' ')

Sample Input 1

4

1 3 4 5

7

Sample Output 1

0 1 1 0

The above indicates that one good of price 3 and one good of price 4 are bought.

Sample Input 2

3

3 4 5

2

Sample Output 2

0

int  caculate(int a_size, int* a, int b, int** result) {
   // a_size : number of different goods
   // a : storing the prices for each good, in the same order as the input good
   // b : money
   // result: storing the number of bought goods, in the same order as the input good
   // return value: the length of result
    
    
}


Question 2 / 2 (Amazon Campus(16):Dequeue game)

Suppose several students stand in a queue and we get an integer indicator n. Student in header of the queue starts to count number from 0. When the number counted by a student is equal to n , he/she need to get out from queue. Then the next student continue to count number from 0. Students count number one by one from head until we need to jump back to header again after reach to end of queue(but we don't reset the n to 0). This kind of procedure will iterate until queue is empty. Please print the index of people according to the order of out of queue.

For example,we get a line from standard input like this:

3

5

a

b

c

d

e

The integer in first line is the indicator n, the integer in second line is the size of the students. The line are the names of students, then we can have a queue
'a’,’b’,’c’,’d’,’e’
At first round, start to count from head of queue. Then 'c' get indicator 3 so 'c' need to get out the queue, then queue remains
'a’,’b’,’d’,’e’
At second round, we continue to count from 'd', Then 'a' get indicator 3 so 'a' need to get out the queue, then queue remains
’b’,’d’,’e’
At third round, we continue to count from 'b', then 'e' get indicator 3 so 'e' need to get out the queue, then queue remains
’b’,’d’
At fourth round, we continue to count from  'b', then 'b' get indicator 3 so 'b' need to get out the queue, then queue remains
'd'
At last round, 'd' need to get out the queue

So you should print the sequence of dequeue:

c
a
e
b
d

For example, we get a line from standard input like this:

4

8

a

b

c

d

e

f

g

h

then we need output from standard output like this:

d
h
e
b
a
c
g
f

int  dequeue(int count, int queue_size, char** queue, char*** result) {


}


你可能感兴趣的:(Amazon Campus(2013-Sep-25))