Ms

Published on June 2016 | Categories: Types, Books - Non-fiction | Downloads: 23 | Comments: 0 | Views: 120
of 7
Download PDF   Embed   Report

Comments

Content

Job Processing: At InterviewStreet we have M machines to process the jobs(submissions). These ma chines work in parallel, so as to minimize the overall completion time of all jo bs. N jobs arrive in some order and they need to be fed in these M machines. Jobs ar e assigned to machines in contiguous blocks i.e say first k1 jobs are fed to fir st machine , next k2 jobs to second machine, next k3 jobs to third machine and s o on. All the machines are equal in terms of their processing power and within a singl e machine all jobs are done serially, so the total time a machine takes to finis h all the jobs assigned to it is the sum of processing time of these jobs. Write a program that partitions the given sequence of jobs in M groups and assig n them to M machines in a way that minimizes the time to complete all jobs. Input Format : First line of input contains two space separated integers N and M, N is the numb er of jobs and M is the number of machines. Then follow N lines each containing an integer which is the processing time requ ired to complete that job. Output Format : Output a single integer which is the minimum time at which all jobs can get comp leted. Sample Input : 5 3 3 6 7 5 3 Sample Output : 9

Explanation :

Some ways to partition these 5 tasks in 3 groups are (3 6) (7) (5 3) , (3) (6 7) (5 3), (3) (6 7 5) (3), (3 6 7) (5) (3) etc. In case of partition (3 6) (7) (5 3) first machine complete all the assigned jobs in 9 units of time, second machi ne does that in 7 units of time and the third machine complete all its jobs in 8 units of time. Since these machines work in parallel, the overall completion ti me of all jobs is 9 units of time and this this is also the minimum completion t ime one can achieve.

Constraints :

1 <= M <= N <= 100,000 0 <= T <= 100,000 , T is the time taken by any job to get processed in a machine . HackerVilla Towers: The country of HackerVilla contains of N cities and N - 1 roads between them suc h that there a path between any two cities. With a war by robots approaching, it was decided to build watch towers along each of the roads. In case the enemy at tacked, a watch tower would communicate the information by lighting a torch so t hat all watch towers at the same height could see it and be warned of the attack . Thus, it was necessary that all towers on the path between two watch towers ha ving the same height X should have height lesser than X. Also, it was decided th at no two adjacent towers (built on roads ending at the same city) should have t he same height as communicating information at such a short distance would not r eally be very useful.

All towers should have an positive integral height. Write a program to find the minimum height that the tallest watch tower can have.

Input Format:

The first line contains the number of test cases T. T test cases follow. The fir st line contains N, the number of cities in HackerVilla. The cities are numbered 0..N - 1. The following N - 1 lines contain the description of the roads. The i th line contains two integers a_i and b_i, meaning that there is a road connecti ng cities with numbers a_i and b_i.

Output Format:

Output T lines, one corresponding to each test case containing the required answ er for that test case.

Constraints:

1 <= T <= 100 1 <= N <= 2000 0 <= a_i,b_i < N

Sample Input:

4 4 0 1 1 2 2 3 4 0 1 0 2 0 3 6 0 1 1 2 2 3 2 4 4 5 7 0 1 1 2 2 3 2 4 4 5

3 6

Sample Output:

2 3 3 4

Explanation:

For the first case, the roads 0-1 and 2-3 can have a tower of height 2 units eac h, while the road 1-2 can have a tower of height 1 unit. Thus, the tallest tower has height 2 units.

For the second case, all roads should have a tower of different height as every pair of them is adjacent. Thus, the tallest tower will have height 3.

For the third case, one solution is to build a tower of height 1 on the road 1-2 , build towers of height 2 on roads 0-1 and 2-4, and towers of height 3 on roads 2-3 and 4-5. MagicStones: Apart from the regular prizes if you win the contest, InterviewStreet will give you magical stones, yes the unique prizes not seen in any other contests. There are 3 types of magical stones. Let us call the types A,B and C. You have N stones of each type. Each magical stone has a power associated with it. The pow er of the ith stone of type A,B and C is a_i,b_i and c_i respectively. When you combine three stones of different types having powers a,b and c, you get a stone of type X. The power of this stone is (a^b) + (a^c). Here '^' is the XOR operat or.

You want to form N stones of type X. Write a program to find the maximum total power you can achieve by combining stones optimally

Input Format: The first line contains the number of test cases T. T test cases follow. Each te st case contains an integer N on the first line. The next three lines contain N

integers each, denoting the powers of stones of type A,B and C respectively.

Output Format: Output T lines, containing the maximum power you can achieve for the correspondi ng case.

Constraints: 1 <= T <= 50 1 <= N <= 100 0 <= a_i,b_i,c_i <= 10000000.

Sample Input: 3 1 2 4 5 2 1 2 3 4 5 6 1 7 7 7

Sample Output: 13 22 0

Explanation: For the first example, the power of the resultant stone is (2^4) + (2^5) = 13. For the second example, combine stones a_1,b_1,c_2 and stones a_2,b_2,c_1. The r esultant power is 9 + 13 = 22.

Evacuation: The goal of this problem is, given a network of road and loations, to determine the maximum number of people that can be evacuated. People must be evacuated from evacuation points to rescue points. The list of r oads and the number of people they can carry per hour is provided. Input Format: The first line contains five integers n s t r h, where n is the number of locat ions (each location is given by a number from 0 to n-1), s is the number of loca tions to be evacuated from(evacuation points), t is the number of locations wher e people must be evacuated to( rescue points), r is the number of roads and h is the number of hours since the rescue mission started. The second line contains s integers giving the locations of the evacuation point s. Third line contains t integers giving the location of rescue points. The r following lines contain the road definitions. Each road is defined by 3 in tegers l1 l2 capacity( people/hr), where l1 and l2 are the locations connected b y road( roads are one way ), capacity is the number of people per hour that can fit on the road. h is the number of hours since rescue mission started. You need to find out how many people are saved after h hours. Output Format: The output should contain only 1 line, giving the maximum number of people that can be evacuated in an hour. Sample Input: 5 0 3 0 0 1 1 2 1 2 5 3 4 1 2 2 3 4 10 5 4 5 10

Sample Output:

24

Sponsor Documents

Or use your account on DocShare.tips

Hide

Forgot your password?

Or register your new account on DocShare.tips

Hide

Lost your password? Please enter your email address. You will receive a link to create a new password.

Back to log-in

Close