Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I want to read the data from a file and execute it.Question is as shown.
Can anyone provide the code for the below question.
Input Description: The first line contains an integer t which is the number of test cases.
Each test case begins with a line containing three integers: number of Initial Reactants(S), Final Products (D) and the total number of elements (N). Then S+D lines follow, first S lines contain IDs of Initial reactant (0 based) and next D lines contain ID's of Final products (0 based). Then follows a line containing an integer R which is number of reactions possible. Then follow R lines, each containing three integers, the Substance(S), the converted substance(C) and the activation energy (A) units required for the reaction. 0 ≤ S, C < N.
Output Description For each test case, output in a different line, 2 integers (a, b) separated by spaces where a is the minimum upper value and b is the minimum number of conversions required for corresponding a. In case that all final products are not obtainable for any value of upper bound, Print a single line with message "Excessive Energy.”
Sample Input
1
2 2 6
1
3
0
3
6
1 2 2
2 4 3
4 5 1
4 2 2
3 0 4
5 0 1Sample Output
4 5
Solution:
Here in this example we have a single test case "t" shown as 1 in the sample input. The 3 integers in the test case are 2 (Initial reactant), 2 (Final Products) and 6 (No. of elements).There are two ID's each for Initial Reactant (1 and 3 are the ID's) and Final Products (0 and 3 are the ID's).
Number of reactions possible between Substance, Converted Substance and Activation Energy are 6 and is represented as R.
In each of the reactions possible the Substance should be greater than or equal to 0 and Converted Substance should be less than the total number of elements that is 6.
Output: Output should be two integers a and b where a represents activation energy and b represents converted substance.
a is the minimum upper value among all 6 reactions that is 4.
b is the minimum number of conversions required for corresponding activation energy(4) that is 5. (5 reactions are required).
So the output would be (4 5).
Output should be printed on a different line for each test case and in this sample there is only one test case, so the output should be printed in a single line separated by a blank space.
Last line says incase all final products are not obtainable for any value of upper bound, print a message "Excessive Energy" that is compare the activation energy(A) with the id's of the final products(0 and 3). Activation energy=4 and final product id's are 0 and 3, so 4 is not equal to 0 or 3.so output should be printed as (4 5).
If the Activation energy 4 and final product id's 0 or 3 were equal then we should print the message "Excessive Energy".

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |