1. Title Description: Click to open the link
2. Problem-solving ideas: The subject is a math problem. The experiment shows that the second square can be placed exactly between the first square and the bottom ray, no matter where the first square is placed. The more the first square is placed, the greater the shadow in the middle. Therefore, when the diagonal of the first square and the second square coincide, the shadow area is maximized. It is not difficult at this point to calculate the area of the shaded part by the geometric relation column.
In fact, you can also change a way of understanding, first of all the small squares of Bengchang and for L, then the large square with L as the edge length of the shadow area is determined, and these small squares can be exactly along the diagonal of the large square, you can calculate the remaining portion of the shadow area. The sum of the two shaded areas is the answer. The detailed section of the procedure is shown in code.
3. Code:
#define _crt_secure_no_warnings #include <iostream> #include <algorithm> #include <string> #include <sstream> #include <set> #include <vector> #include <stack> #include <map> #include < queue> #include <deque> #include <cstdlib> #include <cstdio> #include <cstring> #include < cmath> #include <ctime> #include <functional>using namespace std; #define N 10+5double d[n];int n;double xa , ya, XB, yb;double ans;void update (double len)//Calculates the shadow area in the corner of a square with Len as the side length {double x1, y1, x2, y2;double e1 = ya/xa, e2 = YB /xb;if (E1 < E2) {Swap (e1, E2); Swap (xa, ya); Swap (XB, YB);} X1 = (1 + e2) *len/(e1-e2); x2 = x1 + len;y1 = e1*x1, y2 = E2*x2;ans = (len + x2) *y1/2-LEN*LEN-X2*Y2/2;} int main () {//freopen ("T.txt", "R", stdin), while (~SCANF ("%d", &n) && N) {scanf ("%lf%lf%lf%lf", &xa, &ya, &XB, &yb); ans = 0.0;memset (d, 0, sizeof (d));d ouble L = 0.0;for (int i = 0; i < n; i++) {scanf ("%lf", &A Mp;d[i]); L + = D[i];} Update (L);d ouble res = l*l;for (int i = 0; i < n; i++) Res-= d[i] * D[i];ans + = res/2;//The area of the shadow of the second part printf ("%.3lf\n", ans) ;} return 0;}
Exercise 10-3 angle and square UVa1643