20 Mar 2016

Naughty Sid and SEV


/*

Sid is a very naughty, plump and food-loving boy. Today, his mother has made the special snack SEV. She fills this SEV up to a height ‘H’ cm in a transparent cubical closed box of edge ‘a’ cm (Fig 1) . When Sid asks mother for the SEV, she gives him a little and tells him: ”Only this much for today.” 
 
However Sid is not satisfied. 

He waits for his mother to go out shopping and sneaks into the kitchen. He knows that his mother will scold him if she discovers that he has eaten the SEV without her permission. However, he just can't resist the temptation. He suddenly gets an idea : “If I eat the SEV up to a height ‘h’ from bottom (ie. 'h' height of SEV will be left in the box after he's done eating Fig.2), and then reorganize the SEV (as shown in (Fig.3)), Mom won’t realize that I have eaten the SEV (as Mom sees the SEV only from FRONT VIEW)!“. Unfortunately for Sid , the SEV can stay stable only up to at a maximum sloping angle of THETA_MAX degrees (acute angle) with respect to the ground (horizontal). Help Sid by telling him the maximum amount of SEV he can eat by telling him the appropriate height ‘h’ from bottom up to which he can eat the SEV.
enter image description here

Input:
First line consisting of t, the number of test cases. Each test case comprising of a single line containing space separated integers a, H and THETA_MAX.

Output:
A single line for every test case, consisting of the value of the smallest integer greater than or equal h.

Constraints:
1<=t<=100000
20 <= a <= 100,
0 < H <= a,
0<= THETA_MAX ( in degrees ) < 90.
 
*/


#include <stdio.h>
#include <math.h>
#define PI 3.141593


int main()
{   
    int t,a,H,THETA_MAX,i,h;
    float vol_temp,b_temp,h_temp;


    scanf("%d",&t);
    for(i=0;i<t;i++){
        scanf("%d %d %d",&a,&H,&THETA_MAX);
       
        if(THETA_MAX==0) h=H;
       
        else if(H/tan(THETA_MAX*PI/180)>a){
           
            vol_temp=0.5*H*H/tan(THETA_MAX*PI/180);
            b_temp=H/tan(THETA_MAX*PI/180)-a;
            h_temp=tan(THETA_MAX*PI/180)*b_temp;
            h=ceil((vol_temp-0.5*b_temp*h_temp)/a);
        }
        else {
           
            vol_temp=0.5*H*H/tan(THETA_MAX*PI/180);
            h=ceil(vol_temp/a);
        }

        printf("%d\n",h);
    }
    return 0;
}



Categories: , ,

1 comment:

Copyright © UPgradeCODING | Powered by Blogger