K 7-13 day candle (15 points)
https://pintia.cn/problem-sets/14/problems/793
AC Code:
1 #include <cstdio> 2 #include <cmath> 3 #include <algorithm> 4 using namespace std; 5 int main() 6 { 7 double open,high,low,close; 8 scanf("%lf %lf %lf %lf",&open,&high,&low,&close); 9 if(open>close) printf("BW-Solid"); 10 else if(open==close) printf("R-Cross"); 11 else printf("R-Hollow"); 12 if((high>open&&high>close)&&(low<open&&low<close)) printf(" with Lower Shadow and Upper Shadow\n"); 13 else if(high>open&&high>close) printf(" with Upper Shadow\n"); 14 else if(low<close&&low<open) printf(" with Lower Shadow\n"); 15 return 0; 16 }
7-18 dichotomy single polynomial (20 minutes)
https://pintia.cn/problem-sets/14/problems/798
AC Code:
1 #include <cstdio> 2 #include <cstring> 3 #include <cmath> 4 #include <algorithm> 5 using namespace std; 6 double fal(double a3,double a2,double a1,double a0,double x) 7 { 8 double value=a3*x*x*x+a2*x*x+a1*x+a0; 9 return value; 10 } 11 int main() 12 { 13 double a3,a2,a1,a0,x; 14 double low,high,mid; 15 double threshold=0.001; 16 double value1,value2,value3; 17 scanf("%lf %lf %lf %lf",&a3,&a2,&a1,&a0); 18 scanf("%lf %lf",&low,&high); 19 while(high-low>=threshold) 20 { 21 value1=fal(a3,a2,a1,a0,low); 22 value2=fal(a3,a2,a1,a0,high); 23 if(value1*value2==0){ 24 if(value1==0){ 25 printf("%.2f\n",low); 26 break; 27 } 28 else if(value2==0) 29 { 30 printf("%.2f\n",high); 31 break; 32 } 33 } 34 else{ 35 if(value1*value2<0) 36 { 37 mid=(high+low)/2; 38 value3=fal(a3,a2,a1,a0,mid); 39 if(value3==0) 40 { 41 printf("%.2f\n",mid); 42 break; 43 } 44 else if(value1*value3<0) high=mid; 45 else if(value2*value3<0) low=mid; 46 } 47 else if(value1*value2>0) break; 48 } 49 } 50 if(high-low<threshold){ 51 // if(fal(a3,a2,a1,a0,low)==0) printf("%.2lf\n",low); 52 //else if(fal(a3,a2,a1,a0,high)==0) printf("%.2lf\n",high); 53 printf("%.2f\n",(low+high)/2); 54 } 55 return 0; 56 }
My day, my card this problem for a long time, the first few submitted are partially true, does not consider the case when the endpoint function value is 0, then added a conditional judgment in the while loop, and then submit the output did not even answer, then I think it is not a double input and output formatting issues, changed or answer is not output, submit report WA, then I debug it, found value1 and value2 values simply not right, explain the program start function value are wrong, then I useless pow function, but directly to pow (x, 3) expressed as x * x * x, re-export, actually AC. Also filed out, and then use the Internet Baidu pow function, this is my search to:
If the base x is negative and y is not an integer index, it will lead to error domain error. If the index base x and y are 0, it may result in an error domain error, or may not; this is related with the realization of the library. If the base x is 0, y index is negative, could result in domain error pole error or error, it may not; this is related with the realization of the library. If the return value ret is too big or too small, it will result in an error range error