codechef program #19:Grade The Steel;codechef program #20: Minimum Maximum

FLOW014

#1:PROBLEM STATEMENT:


A certain grade of steel is graded according to the following conditions.
  • Hardness must be greater than 50.
  • Carbon content must be less than 0.7.
  • Tensile strength must be greater than 5600.



  • The grades are as follows:
  • Grade is 10 if all three conditions are met.
  • Grade is 9 if conditions (i) and (ii) are met.
  • Grade is 8 if conditions (ii) and (iii) are met.
  • Grade is 7 if conditions (i) and (iii) are met.
  • Garde is 6 if only one condition is met.
  • Grade is 5 if none of three conditions are met.


  • Write a program, if the user gives values of hardness, carbon content and tensile strength of the steel under consideration and display the grade of the steel. 

    Input

    The first line contains an integer T, total number of testcases. Then follow T lines, each line contains three numbers hardnesscarbon content and tensile strength of the steel.

    Output

    Print Grade of the steel depending on Conditions.

    Constraints

    •  T  1000
    • 1 hardness, carbon content, tensile strength  10000

    Example

    Input
    
    3 
    53 0.6 5602
    45 0 4500
    0 0 0 
    Output
    
    10
    6
    6

    My Solution:

    import java.util.Scanner;


    public class gts
    {

    public static void main(String args[])
    {
    Scanner sc=new Scanner(System.in);
    int counter=sc.nextInt();

    for(int i=0;i { int g=0;
    boolean ab=false,cb=false,dd=false;
    float a=sc.nextFloat(),b=sc.nextFloat(),c=sc.nextFloat();
    if(a>50) ab=true;
    if(b<.7) cb=true;
    if(c>5600) dd=true;

    if(ab&&cb&&dd) g=10;else if(ab&&cb) g=9;else if(cb&&dd) g=8;else if(ab&&dd) g=7;else if(ab||cb||dd) g=6;else  g=5;
    System.out.println(g);
    }

    }
    }
    #2:PROBLEM STATEMENT:
    Chef loves to play with arrays by himself. Today, he has an array A consisting of N distinct integers. He wants to perform the following operation on his array A.
    • Select a pair of adjacent integers and remove the larger one of these two. This decreases the array size by 1. Cost of this operation will be equal to the smaller of them.
    Find out minimum sum of costs of operations needed to convert the array into a single element.

    Input

    First line of input contains a single integer T denoting the number of test cases. First line of each test case starts with an integer N denoting the size of the array A. Next line of input contains N space separated integers, where the ith integer denotes the value Ai.

    Output

    For each test case, print the minimum cost required for the transformation.

    Constraints

    • 1 ≤ T ≤ 10
    • 2 ≤ N ≤ 50000
    • 1 ≤ Ai ≤ 105

    Subtasks

    • Subtask 1 : 2 ≤ N ≤ 15 : 35 pts
    • Subtask 2 : 2 ≤ N ≤ 100 : 25 pts
    • Subtask 3 : 2 ≤ N ≤ 50000 : 40 pts

    Example

    Input
    2
    2
    3 4
    3
    4 2 5
    
    Output
    3
    4
    

    Explanation

    Test 1 : Chef will make only 1 move: pick up both the elements (that is, 3 and 4), remove the larger one (4), incurring a cost equal to the smaller one (3).

    My Solution:
    import java.util.Scanner;
    import java.util.Arrays;

    public class MinMax 
    {
    public static void main(String args[])
    {
    Scanner sc=new Scanner(System.in);
    int counter=sc.nextInt();
    for(int i=0;i
    {
    int count=sc.nextInt();
    long arr []=new long[count];
    for (int j=0;j
    {
    arr[j]=sc.nextInt();
    }
    Arrays.sort(arr); 
    System.out.println(arr[0]*(count-1));
    }
    }
    }

    posted by lol ik


    Comments

    Popular Posts