Steps 4.1 is mainly about binary and triples. The idea of binary is very important and commonly used. In addition, you must pay attention to the accuracy during Floating Point calculation.
4.1.1 HDU 2199 can you solve this equation
The function increases monotonically. When F (0)> 0 or F (100) <0, there is no solution. The second answer is enough, and the precision is 1e-6.
4.1.2 hdu2899 strange Function
Convex function, which can be done by the three-way method. I'm the first derivative, and its derivative is monotonous. so I can find the X with the derivative = 0 and then substitute it into the original formula.
4.1.3 hdu1967 pie
Ask how much pie each person can divide, first sort the area, and then obtain the answer in two places between 0 and the maximum pie area, and calculate whether each value can reach F + 1, of course, the priority is to remove the larger pie... in addition, when calculating the circular area, if Pi = ACOs (-1) is directly written to 3.141592653, the accuracy is incorrect.
4.1.4 hdu2141 can you find it
Binary Search: Calculate and store all the results of A + B, and then sort the results of K. Then, perform binary search for K-C (a + B = k-C) 500 ms +
Of course, a better way is to use the hash table to search for the complexity of O (1). This question should be a bit of a binary search ..
# Include <cstdio> # include <algorithm> using namespace STD; typedef _ int64 ll; const int maxn = 505; ll a [maxn], B [maxn], c [maxn], AB [maxn * maxn]; int CAS = 1, n, M, L, KS, K, low, high, mid; bool findk (INT X) {LOW = 0, high = L * n; while (high-low> 1) {int mid = (high + low)/2; if (AB [Mid] = x) return true; If (AB [Mid]> X) High = mid; else low = mid;} return false;} int main () {While (scanf ("% d", & L, & N, & M )! = EOF) {for (INT I = 0; I <L; I ++) scanf ("% i64d", & A [I]); For (INT I = 0; I <n; I ++) scanf ("% i64d", & B [I]); For (INT I = 0; I <m; I ++) scanf ("% i64d", & C [I]); // store the results of A + B and sort them for (INT I = 0; I <L; I ++) for (Int J = 0; j <n; j ++) AB [I * n + J] = A [I] + B [J]; sort (AB, AB + L * n); printf ("case % d: \ n", CAS ++); scanf ("% d", & KS); While (ks --) {scanf ("% d", & K); int find = 0; // In [A + B], check whether the value is equal to the value of c-k for (INT I = 0; I <m; I ++) {If (findk (k-C [I]) {find = 1; break ;}} printf (find? "Yes \ n": "No \ n ");}}}
4.1.5 hdu2298 Toxophily
I did it directly as a math question (physics question ?..) Orthogonal Decomposition then removes y and turns it into a quadratic equation. You can solve this equation. pay attention to several issues. Delta has no solution when it is <0. When x = 0, the equation is not a quadratic equation, and can be directly reached at the origin, if it is perpendicular to the Y axis, and the coordinate is in the first quadrant, It is removed as a positive number. Select a smaller positive number ..
This question is simple... it's not easy to think about it ....
# Include <cstdio> # include <cmath> using namespace STD; const double G = 9.8; int CAS; Double X, Y, V, A, B, C, ans1, ans2, delta; int main () {scanf ("% d", & CAS); While (CAS --) {scanf ("% lf", & X, & Y, & V); // when x = 0, the equation is not a quadratic equation if (x = 0) {If (y = 0) printf ("0.000000 \ n"); If (Y> 0) printf ("%. 6lf \ n ", ACOs (-1)/2); continue;} // convert to a quadratic equation. The Unknown number is Tan (alpha); A = G * x * X; B =-x * 2 * V; C = 2 * y * V + G * x * X; Delta = B * B-4 * a * C; // Delta <0 unsolvable if (delta <0) printf ("-1 \ n"); else {// select a small positive solution (x> = 0, y> = 0, Tan (alpha)> = 0) ans1 = (-B-SQRT (B * B-4 * a * C)/2/; ans2 = (-B + SQRT (B * B-4 * a * C)/2/a; If (ans2 <0) printf ("-1 \ n "); else if (ans1 <0) printf ("%. 6lf \ n ", atan (ans2); else printf (" %. 6lf \ n ", atan (ans1) ;}} return 0 ;}
4.1.6 hdu1597 find the nth Digit
Water question, pay attention to data overflow issues
4.1.7 hdu2438 turn the corner
It is really difficult to make this question without good mathematical skills.
Then list the equation of an edge on the car, and then find the maximum value of the intersection of the equation and Y = X. It is obviously a convex function, which can be solved by a three-way... I don't know why. At the beginning, we started to use the binary left, right. We made wa in the binary mid and right, and then changed it to the average three points .. theoretically, it should be okay ..
# Include <cstdio> # include <cmath> using namespace STD; Double X, Y, L, D, mid, midmid, low, high; double CAL (double JD) {return (L * sin (JD) + d/cos (JD)-x)/TAN (JD);} int main () {/* creates a coordinate system based on the origin in the lower right corner, y = xtan (A) + L * sin (A) + d/cos (a) And then substitute y = x, returns the maximum value of X about angle A (0 <= A <= PI/2); */while (~ Scanf ("% lf", & X, & Y, & L, & D) {high = ACOs (-1.0)/2.0, low = 0.0; // obtain the Extreme Value of the three-way method. While (high-low> 1e-4) {mid = (high-low) * 1.0/3.0 + low; midmid = (high-low) * 2.0/3.0 + low; If (CAL (MID)> CAL (midmid) High = midmid; else low = mid;} printf (Y-cal (low)> 0? "Yes \ n": "No \ n");} return 0 ;}
4.1.8 hdu3400 line belt
A three-point good question, nested three-point solution... I can't think of this question without reading Daniel's article ..
This article explains a more detailed http://hi.baidu.com/myzone2009/blog/item/1f9560ccdf5d045d0eb34535.html
I use t as the independent variable. In this way, there is a small problem. When finding the distance not on the line segment, we will divide the distance. Since there is division, we must pay attention to the Division 0 problem, therefore, we need to add a small precision when finding the distance .. otherwise, wa ..
# Include <cstdio> # include <cmath> # include <cstdlib> using namespace STD;/* f (x) = g (x) + H (y) g (x) monotonic, H (Y) is convex, f (x) is also convex, where G (x) is the time on AB, H (y) is the time on the CD plus the time on the plane */Double ax, ay, BX, by, CX, Cy, dx, Dy, P, Q, R; double L1, l2, H1, H2, M11, M12, m21, m22; double DIS (double X1, double Y1, double X2, double Y2) {return SQRT (1e-6 + (x1-x2) * (x1-x2) + (y1-y2) * (y1-y2);} double CAL (double M1, double m2) {double x1, x2, Y1, Y2; x1 = AX + m1 * p * (bx-Ax)/DIS (ax, ay, BX, by); Y1 = Ay + m1 * p * (by-ay) /DIS (ax, ay, BX, by); x2 = dx + m2 * Q * (CX-dx)/DIS (CX, Cy, dx, Dy ); y2 = Dy + m2 * Q * (Cy-dy)/DIS (CX, Cy, dx, Dy); Return DIS (x1, Y1, X2, Y2)/R ;} double calsf (double m) {L2 = 0, H2 = DIS (CX, Cy, dx, Dy)/Q; while (h2-l2> 1e-6) {m21 = (h2-l2) * 1.0/3.0 + L2; m22 = (h2-l2) * 2.0/3.0 + L2; If (m21 + CAL (M, m21) <m22 + CAL (M, m22 )) h2 = m22; else L2 = m21;} return H2 + CAL (M, H2);} int main () {int CAS; scanf ("% d", & CAS ); while (CAS --) {scanf ("% lf", & ax, & ay, & BX, & ); scanf ("% lf", & CX, & cy, & dx, & Dy); scanf ("% lf", & P, & Q, & R); L1 = 0, H1 = DIS (ax, ay, BX, by)/P; while (h1-l1> 1e-6) {M11 = (h1-l1) * 1.0/3.0 + L1; M12 = (h1-l1) * 2.0/3.0 + L1; If (M11 + calsf (m11) <m12 + calsf (m12) H1 = m12; else L1 = M11;} printf ("%. 2lf \ n ", H1 + calsf (H1);} return 0 ;}