Computer Science, asked by yogsy7h, 1 year ago

WHAT IS THE PROGRAM FOR THIS....?

Problem : Sheldon Cooper and his beverage paradigm

Sheldon Cooper, Leonard Hofstadter and Penny decide to go for drinks at Cheese cake factory. Sheldon proposes to make a game out of this. Sheldon proposes as follows,

To decide the amount of beverage they plan to consume, say X.
Then order for a random number of different drinks, say {A, B, C, D, E, F} of quantities {a, b, c, d, e, f} respectively.
If quantity of any three drinks add up to X then we'll have it else we'll return the order.
E.g. If a + d + f = X then True else False


You are given

Number of bottles N corresponding to different beverages and hence their sizes
Next N lines, contain a positive integer corresponding to the size of the beverage
Last line consists of an integer value, denoted by X above

Your task is to help find out if there can be any combination of three beverage sizes that can sum up to the quantity they intend to consume. If such a combination is possible print True else False

Input Format:

First line contains number of bottles ordered denoted by N
Next N lines, contains a positive integer Ai, the size of the ith bottle
Last line contains the quantity they intend to consume denoted by X in text above



Output Format:
True, if combination is possible
False, if combination is not possible

Constraints:

N >= 3

Ai > 0

1 <= i <= N

X > 0


Sample Input and Output

SNo. Input Output
1
6
1
4
45
6
10
8
22


True

2
4
1
3
12
4
14


False



Explanation for sample input and output 1:

The sum of 2nd, 5th and 6th beverage size is equal to 22. So the output will be True.

Explanation for sample input and output 2:

Since no combination of given beverage sizes sum up to X i.e. 14, the output will be False.

Note:

Please do not use package and namespace in your code. For object oriented languages your code should be written in one class.

Note:

Participants submitting solutions in C language should not use functions from / as these files do not exist in gcc

Note:

For C and C++, return type of main() function should be int.

Answers

Answered by dilleswarraomandala
4
There are N numbers placed on a table.Since two players are playing the game, they will make their moves alternatively.In one move a player can perform the following operation.A player will choose a number from the table and will replace that number with one of its divisor. For example, 6 can be replaced with 1, 2, or 3 (since these are the divisors of 6). Similarly, 12 can be replaced with 1, 2, 3, 4 or 6.It is mandatory that the player has to replace the number.A player cannot put back the same number on table.As 1 does not have any divisor other than itself, a player cannot replace 1 with any other number. So soon a situation will arise when there will be only all 1s on the table. In that situation the player will not be able to make any move. The player who will not be able to make the move, loses.Both the players are masters of this game. So they will play the game optimally.Aman will make the first move of the game.

yogsy7h: well......bro
Answered by senthilpandi
0

Answer:

#include<stdio.h>

#include<conio.h>

#include<stdlib.h>

void main()

{

int i,n,q,l,k,j,*a=NULL;

clrscr();

printf("enter the no of entries: ");

scanf("%d",&n);

a=(int*)calloc(n,sizeof(int));

for(i=0;i<n;i++)

{

scanf("%d",&a[i]);

}

printf("enter the quantity to be consumed\n");

scanf("%d",&q);

for(i=0;i<n;i++)

{

if(a[i]>q)

{

a[i]=a[n-1];

n--;

i--;

}

}

for(i=0;i<n;i++)

{

k=a[i]; //selecting 1st element

for(j=i+1;k+a[j]<q&&j<n;j++)

{

k=k+a[j]; //2nd element decided

for(l=j+1;l<n;l++)

{

if(k+a[l]==q) //checking for 3rd element

{

printf("\tyes\n");

goto end;

}

}

k=k-a[j];

}

k=k-a[i];

}

printf("\tno");

end:getch();

exit(0);

}

Similar questions