Mars Stone
Rob has gone to Mars to collect some stones. The bag he is carrying can hold a maximum weight of M.
There are M stones weighing from 1 to Min Mars. There are N stones on Mars that are similar to the
ones on Earth. Find the number of stones he can bring from Mars such that none of them are similar to
any stone on Earth.
Input Specification:
inputi: M. denoting the size of the bag and the number of different stone
weights present on Mars.
input2: N, denoting the number of common stones on Earth and Mars.
input3: An N element array containing the list of the weights of the common
stones,
Output Specification:
Your function should return the maximum unique stones that can be collected
from Mars.
Answers
Answer:
Rupam and Ankit are both fond of collecting stones. They both follow this hobby diligently and go out finding stones together. So, one fine day they decided to play a small game.They decided to weigh each of the stones and note them down in a notepad, and then at the end of the day both of them will compare their notes.
They will check how many stones of a particular weight are there. Then they will compare the weight of the stone occurring maximum number of times (you can consider stones of similar weight to be similar). In case that all different stones occur exactly same number of times, the stone with maximum weight will be considered for comparison. The person with higher weighing stone wins, else there will be a tie. You need to determine the result.
INPUT:
The first line of input consists of a single integer T denoting number of test cases. Each test case consists of three lines. First line consists of a single integer N denoting the number of stones. The second line consists of N space separated integers denoting the weights of stones collected by Rupam. The third line consists of N space separated integers denoting the weights of stones collected by Ankit.
Answer:
def mars():
a=[1,2,3,4,5,6,7,8,9,10]
dup=[]
sack=[]
sack2=[]
b=[i for i in a if i not in dup]
print("All stones on Mars : ",a)
print("")
n = int(input("Enter number of elements : "))
print("")
for i in range(0, n):
ele = int(input("Duplicate stone no. {} : ".format(i+1)))
dup.append(ele)
b=[i for i in a if i not in dup]
print("")
print("Duplicate stones on Earth : ",dup)
print("")
print("Remaining stones : ",b)
m=max(b)
for i in b:
for j in b[1:]:
for k in b[2:]:
for x in b[3:]:
if i+j+k+x<m:
sack.extend(([[i,j,k,x]]))
elif i+j+k<=m:
sack.extend(([[i,j,k]]))
elif i+j<=m:
sack.extend(([[i,j]]))
print("")
max_cap=max(sack, key=len)
for p in sack:
if len(max_cap)==len(p):
suck.append(p)
res=[]
for i in sack2:
if i not in res:
res.append(i)
print ("Maximum possible combinations of stones : ",str(res))
return res
mars()