Advertisement
Guest User

Untitled

a guest
Nov 25th, 2015
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.82 KB | None | 0 0
  1. import java.util.*;
  2. public class prob7{
  3.     public static int p,q,r,s,t,u;
  4.     public static double f(int x){
  5.         return p*Math.exp(-x) + q*Math.sin(x)+r*Math.cos(x)+s*Math.tan(x)+t*x*x+u;
  6.     }
  7.     public static int bi(){
  8.         int low=0;
  9.         int high=1;
  10.         while(low+high>0.0000001){
  11.             int x=(low+high)/2;
  12.             if(f(low)*f(x)<=0){
  13.                 high=x;
  14.             }
  15.             else{
  16.                 low=x;
  17.             }
  18.         }
  19.         return (low+high)/2;
  20.     }
  21.  
  22.     public static void main(String args[]){
  23.         Scanner input=new Scanner(System.in);
  24.         int n=input.nextInt();
  25.         while(n>0){
  26.             p=input.nextInt();
  27.             q=input.nextInt();
  28.             r=input.nextInt();
  29.             s=input.nextInt();
  30.             t=input.nextInt();
  31.             u=input.nextInt();
  32.             if(f(0)*f(1)>0){
  33.                 System.out.println("Impossivel");
  34.             }
  35.             else{
  36.                 double out=bi();
  37.                 System.out.printf("%.4lf\n", out);
  38.             }
  39.             n--;
  40.         }
  41.            
  42.    
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement