HDOJ 2199 HDU 2199 Can you solve this equation? ACM 2199 IN HDU
Can you solve
this
equation
?
Time Limit:
2000
/
1000
MS (Java
/
Others) Memory Limit:
32768
/
32768
K (Java
/
Others)Total Submission(s):
322
Accepted Submission(s):
148
Problem DescriptionNow,given the equation
8
*
x
^
4
+
7
*
x
^
3
+
2
*
x
^
2
+
3
*
x
+
6
==
Y,can you find its solution between
0
and
100
;Now please
try
your lucky. InputThe first line of the input contains an integer T(
1
<=
T
<=
100
) which means the number of test cases. Then T lines follow, each line has a real number Y (fabs(Y)
<=
1e10); OutputFor each test
case
, you should just output one real number(accurate up to
4
decimal
places),which
is
the solution of the equation,or “No solution
!
”,
if
there
is
no solution
for
the equation between
0
and
100
. Sample Input
2
100
-
4
Sample Output
1.6152
No solution
!
제목 분석:
분명 합 니 다. 이것 은 2 점 검색 문제 입 니 다. 하지만 다음 문제 의 데 이 터 를 주의 하 세 요!!1e 10 의 실수!!그리고 정밀도 가 0.0001 이 어야 하기 때문에 2 점 이 라 고 해도 데이터 양 이 많 습 니 다. 만약 에 사용 하면...
일반적인 재 귀 방법 이 요? 안 타 깝 게 도 RE..................................................... 어 쩔 수 없어, 순환 할 수 밖 에 없어.
다음은 재 귀적 RE 코드 입 니 다.
#include <iostream>
#include <cmath>
using namespace std;
#define POW(x) ( (x) * (x) )
#define POW3(x) ( POW(x) * (x) )
#define POW4(x) ( POW(x) * POW(x) )
double y = 0; bool douEql ( double a,double b ) { if ( fabs( a - b ) <= 1e-6 ) return true; return false; } double cal ( double n ) { return 8.0 * POW4(n) + 7 * POW3(n) + 2 * POW(n) + 3 * n + 6 ; } double biSearch ( double l, double r ) { if ( douEql ( l,r ) ) { if ( douEql ( y, cal ( l ) ) ) return l; return -1; } double mid = ( l + r ) / 2.0; if ( douEql ( y, cal ( mid ) ) ) return mid; else if ( cal ( mid ) > y ) return biSearch ( l,mid - 0.0001 ); else return biSearch ( mid + 0.0001, r ); } int main () { int T;
scanf ( "%d",&T ); while ( T -- ) {
scanf ( "%lf",&y ); if ( cal(0) >= y && cal(100) <= y ) {
printf ( "No solution!
" ); continue; } double res = biSearch ( 0.0, 100.0 ); if ( res == -1 )
printf ( "No solution!
" ); else
printf ( "%.4lf
",res ); } return 0; }
AC 코드 는 다음 과 같 습 니 다.
MiYu 오리지널, 댓 글 은새하얀 집
<
iostream
>
#include
<
cmath
>
using
namespace
std;
#define
POW(x) ( (x) * (x) )
#define
POW3(x) ( POW(x) * (x) )
#define
POW4(x) ( POW(x) * POW(x) )
double
y
=
0
;
double
cal (
double
n ){
return
8.0
*
POW4(n)
+
7
*
POW3(n)
+
2
*
POW(n)
+
3
*
n
+
6
;}
int
main (){
int
T; scanf (
"
%d
"
,
&
T );
while
( T
--
) { scanf (
"
%lf
"
,
&
y );
if
( cal(
0
)
>
y
||
cal(
100
)
<
y ) { printf (
"
No solution!
"
);
continue
; }
double
l
=
0.0
, r
=
100.0
,res
=
0.0
;
while
( r
-
l
>
1e
-
6
) {
double
mid
=
( l
+
r )
/
2.0
; res
=
cal ( mid );
if
( res
>
y ) r
=
mid
-
1e
-
6
;
else
l
=
mid
+
1e
-
6
; } printf (
"
%.4lf
"
,( l
+
r )
/
2.0
); }
return
0
; }
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.