Write a program that plays "Cows and bulls". The user thinks of a number less than 10000, with no two digits identical (like 1234. numbers like 0875 are allowed. But 5456 and 3922 are not because it contains 2 indentical digits). The program starts by guessing a number. The user gives the number of hits and misses. A hit is a number in the right place and a miss is a number in the wrong place. e.g If the the number you thought is 4273 the feedback for 2135 is 0 hit 2 miss 0913 is 1 hit 0 miss 4217 is 2 hit 1 miss Your program should use the feedback provided by the user for the next guess and keep guessing after every feedback till it gets the right number. A good program will get the number in about 7 guesses (on an average).
5) Cows and bulls. This requires some explaining because nobody got it. But actually its not that difficult. You create an array of all possible numbers. Guess one randomly from that list. Based on the feedback reduce your list eliminating the numbers that can't satisfy the feedback. Guess again from the new list. You will hit the right number in 5 to 7 trys.
A Sack is given with a specified volume. And a set of bags are given, each with a specified mass and volume. You have to fill the sack using some of bags such that the total volume of chosen bags is less than or equal to the volume of the sack and their total mass is maximum. Input: Input will be read from a file called "bags.dat". It will contain the number of bags, the volume of the sack, followed by the volume and the mass of the bags. eg. 6 100 10 2 50 10 20 5 40 9 30 5 35 8 Output: Output should be printed on the screen. It will be the number of all the bags to be used. For the given example it will be, 3,4,6
7) Zigzag An n by m matrix with all its elements between 1 to 4 is given. The left top element(1,1) is 1 and right bottom element(m,n) is 4. You have to find out a continuous zigzag path connecting these two elements, such that, 1)small parts of the zigzag are lines connecting two elements. 2)The numbers in the zigzag path should read 1-2-3-4-1-2-3-4... 3)The zigzag must touch all squares. Assume a solution exists. Example : Given: Solution should be: ;1 3 1 2 ;1 3 1-2 |/ \| | 2 1 4 3 2 1 4 3 / \ / 2 3 4 3 2-3 4 3 / /| 4 1 2 4; 4-1-2 4; Input: input should be read from a file called "matrix.dat". The file contains, row no. column no. elements. eg. 4 4 1 3 1 2........ Output: Output should be printed on the screen. Program should print out the row and column numbers of the elements in the order they are visited. eg. (1,1) (2,1) (1,2) (2,3) .....
7) Zigzag. Many people used brute force algorithms. Their code didn't work for a matrix of order 8. One way to do this is to maintain a list of all possible ins and outs for every square. Using the ins of the neigbouring nodes decrease the possible outs for every square. Then use the neighbouring outs to decrease the ins of every square. Do this a few times and you will get very near the solution. Then do a few check and you can get it.
You have "n" numbers having values from 1 to n. You have to write a code to partition it into "m" groups such that sum of numbers in each group is equal to n*(n+1)/(2*m). Assume that numbers n and m are such that n*(n+1)/(2*m) is an integer. Your program should print out the numbers in each group. Or if it is not possible to partition the numbers into m groups, then print out that its not possible. Example : n=20 and m=3 Group 1 : 1,8,11,13,18,19 Group 2 : 2,5,12,14,17,20 Group 3 : 3,4,6,7,9,10,15,16 Input: Two integers n,m. Output: Print out to the screen the numbers in each group in a differnt line. Testing: We will run atleast 5 test cases for this problem. So if you cannot write a generalised code which will take care of all n and m, you can try to write codes based on specific conditions.
8) Partition. An algo which worked very well, was to start by adding the number n(the largest number) to group 1. Then add the next largest number ( n-1 in this case) , and check whether your sum in that group is greater than n(n+1)/(2m). If it is greater, than take out the number and then add the next greatest number and so on till you get the sum equal to n(n+1)/(2m). For the next group, start out similarly, add the largest of the remaining numbers to the group, and keep adding the next largest, till you get the sum.
C-on-test - Intra-IIT Round Brought to you by CSEA, IITB in association with VERITAS software.
Problem 1. ~~~~~~~~~~ With Election fever on its high and politicians running short on time you have write an program which they can use to call junta to come forward and vote... The program should print Come-Sure-Come on a line by itself just once. No leading or trailing spaces. The output is case sensitive i.e. come-sure-come would be regarded as incorrect. As an concerned citizen of this country you should do your bit towards it. Ask yourself, Do you want an elected government or are you apathetic ?
Problem 2. ~~~~~~~~~~ Elections over, mps' elected, the auction house set and the horse-trading is on. All the mp's are seated in a circle. Each belongs to either the H front or the T front of the regional faction of the secular group of the leftist liberal democratic anti-communalist pro-poor progressive party of India. In the center of the circle is THE ONE of the current polity Akal Bechari Bhaggayi (ABB). His aim is to convert all the mp's to either H or T group. But mps' being mps', having had years of experience are not so easy. They always go in pairs (so they can use each other as excuse later). In each step ABB can ask any 2 adjacent mp's to toggle their loyalty. Time however is of the essence. Everyone wants a piece of the action and if ABB doesnot convert fast he will be out of center stage. This is where you come into the picture. You being the brilliant students from IITB can surely use your skills to help him out. Help ABB figure out the minimum number of steps required to achieve his aim. You will be given a string consisting of H's and T's as input on a single line. The size of the input is bounded above by 1600. Consider the input string to be the Circle listed out clockwise from some point. You have to output the number of steps it will take ABB to convert all mp's to one type. The number is to be printed on a line by itself. No leading or trailing data. If it is not possible to do the conversion then output -1. Sample Input: HTTH ~~~~~~~~~~~~~ Sample Output: 1 (for above example. Either pair of T's or H's