-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathTRIGALGE.cpp
75 lines (56 loc) · 1.39 KB
/
TRIGALGE.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// AC, ALGO : Maths, Newton-Raphson method.
/* Some Helpful Links :
https://en.wikipedia.org/wiki/Newton%27s_method
http://www.sosmath.com/calculus/diff/der07/der07.html
*/
// For any clarifications, contact me at : osinha6792@gmail.com
#include<cstdio>
#include<cmath>
using namespace std ;
// Fast I/P Begins
#define get getchar_unlocked
inline int inp( )
{
int n = 0 , s = 1 ;
char p = get( ) ;
if( p == '-' )
s = -1 ;
while( ( p < '0' || p > '9' ) && p != EOF && p != '-' )
p = get( ) ;
if( p == '-' )
s = -1 , p = get( ) ;
while( p >= '0' && p <= '9' )
{
n = ( n << 3 ) + ( n << 1 ) + ( p - '0' ) ;
p = get( ) ;
}
return n * s ;
}
// Fast I/P Ends
int main()
{
int t , i , a , b , c ;
double x1 , x2 , x3 , ans ;
t = inp() ;
while( t-- )
{
a = inp() ;
b = inp() ;
c = inp() ;
x1 = 0 ;
x2 = 2500 ;
for( i = 1 ; i <= 50 ; i++ )
{
x3 = ( x1 + x2 ) / 2 ;
ans = a * x3 + b * sin( x3 ) - c ;
if( ans == 0.000000 || ( x2 - x1 ) / 2 < 0.000001 )
break ;
if( ans > 0 )
x2 = x3 ;
else
x1 = x3 ;
}
printf("%lf\n",x3) ;
}
return 0 ;
}