📄 toj_2803.cpp
字号:
/*2803. The Quadratic Equation Time Limit: 1.0 Seconds Memory Limit: 65536KTotal Runs: 481 Accepted Runs: 313In middle school, Hawk often needs to solve quadratic equation problems.A quadratic equation, is an equation such as aX2 + bX + c = 0.Given the values of a, b, and c, would you please help Hawk determine the value of X ?InputThe first line of the input contains an integer n(n < 1000). The next n lines contain n equations, each equation is denoted by three double valued numbers, a, b, and c. The value of a won't be zero.OutputFor each equation, output a line contains the solution. For quadratic equation, there may be two different values for X, please output the smaller one firstly. Answers must be rounded to three digits after the decimal point. If the equation has no solution, output "No solution!".Sample Input41.0 10.0 5.01.0 2.0 1.02.5 5.8 5.412.0 4.0 -56.0Sample Output-9.472 -0.528-1.000No solution!-2.333 2.000Problem Setter: cnHawkSource: TJU Programming Contest 2007 Preliminary*/#include<cstdio>#include<cmath>int main(){ int i , n; double a , b , c , delta , x1 , x2; scanf( "%d" , &n ); for ( i = 0; i < n; i++ ) { scanf( "%lf%lf%lf" , &a , &b , &c ); delta = b * b - 4 * a * c; if ( delta < 0 ) printf ( "No solution!\n" ); else if ( fabs( delta ) < 1e-8 ) { x1 = - b / 2.0 / a; printf( "%05.3lf\n" , x1 ); } else { delta = sqrt( delta ); x1 = ( - b - delta ) / 2.0 / a; x2 = ( - b + delta ) / 2.0 / a; printf( "%05.3lf %05.3lf\n" , x1 , x2 ); } } return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -