【每日一题】蓝桥杯历年真题题解 -荒岛探测

admin 2023年2月16日19:25:49评论28 views字数 4389阅读14分37秒阅读模式

【每日一题】蓝桥杯历年真题题解 -荒岛探测
点击蓝字 关注我们
【每日一题】蓝桥杯历年真题题解 -荒岛探测

今日「每日一题」来啦!历年真题题目:荒岛探测。还没有加入专属刷题群的小伙伴,记得扫码哟~(每天会在群里发蓝桥杯历年真题)

【每日一题】蓝桥杯历年真题题解 -荒岛探测

题目描述

【每日一题】蓝桥杯历年真题题解 -荒岛探测

解题思路

【每日一题】蓝桥杯历年真题题解 -荒岛探测

【每日一题】蓝桥杯历年真题题解 -荒岛探测

【每日一题】蓝桥杯历年真题题解 -荒岛探测

【每日一题】蓝桥杯历年真题题解 -荒岛探测

【每日一题】蓝桥杯历年真题题解 -荒岛探测

参考代码

1、Java组

import java.util.*;
public class Main { private static final double eps = 1e-6; private static double xa; private static double ya; private static double xb; private static double yb; private static double L; private static double A; private static double ans; private static double[] x = new double[6]; private static double[] y = new double[6]; private static double[] Y = new double[6];
private static double dist(double a, double b, double c, double d) { return Math.sqrt((c - a) * (c - a) + (d - b) * (d - b)); }
private static double get(double now, int pos1, int pos2) { if (Math.abs(x[pos1] - x[pos2]) <= eps && Math.abs(x[pos1] - now) <= eps) { return 1002; } if (now <= Math.min(x[pos1], x[pos2]) || now >= Math.max(x[pos1], x[pos2])) { return 1002; } return (y[pos2] - y[pos1]) / (x[pos2] - x[pos1]) * (now - x[pos2]) + y[pos2]; }
private static boolean ok1(double now) { double xx = (xa + xb) / 2; double yy = (ya + yb) / 2; double a = L / 2; double c = dist(xa, ya, xb, yb) / 2; double b = Math.sqrt(a * a - c * c); double mid = 1.0 - (now - xx) * (now - xx) / (a * a); if (mid <= 0) { return false; } mid = Math.sqrt(mid) * b; Y[1] = yy - mid; Y[2] = yy + mid; return true; }
private static boolean ok2(double now) { int cnt = 2; for (int i = 1; i <= 3; i++) { int nex = i + 1 == 4 ? 1 : i + 1; double mid = get(now, i, nex); if (mid - 1000 > eps) { continue; } if (cnt == 3 && Math.abs(mid - Y[cnt]) <= eps) { continue; } Y[++cnt] = mid; } if (cnt != 4) { return false; } return true; }
private static double get_angle(double a, double b, double c, double d) { double now = Math.acos((c - a) / dist(a, b, c, d)); if (d - b < 0) { return 2 * Math.acos(-1) - now; } return now; }
private static void init() { A = get_angle(xa, ya, xb, yb); double dis1 = dist(0, 0, xa, ya); double dis2 = dist(0, 0, xb, yb); double S1 = get_angle(0, 0, xa, ya) - A; double S2 = get_angle(0, 0, xb, yb) - A; xa = dis1 * Math.cos(S1); ya = dis1 * Math.sin(S1); xb = dis2 * Math.cos(S2); yb = dis2 * Math.sin(S2); }
private static void change(int pos) { double dis = dist(0, 0, x[pos], y[pos]); double S = get_angle(0, 0, x[pos], y[pos]) - A; x[pos] = dis * Math.cos(S); y[pos] = dis * Math.sin(S); }
private static double calc(double now) { if (!ok1(now)) { return 0; } if (!ok2(now)) { return 0; } double ma = Math.max(Math.min(Y[1], Y[2]), Math.min(Y[3], Y[4])); double mi = Math.min(Math.max(Y[1], Y[2]), Math.max(Y[3], Y[4])); if (mi - ma <= eps) { return 0; } return mi - ma; }
public static void main(String[] args) { Scanner cin = new Scanner(System.in); xa = cin.nextDouble(); ya = cin.nextDouble(); xb = cin.nextDouble(); yb = cin.nextDouble(); L = cin.nextDouble(); init(); for (int i = 1; i <= 3; i++) { x[i] = cin.nextDouble(); y[i] = cin.nextDouble(); change(i); } if (L <= eps || dist(xa, ya, xb, yb) >= L) { System.out.print("0.00n"); return; } for (double i = -1000; i <= 1000; i += 0.001) { ans += calc(i) * 0.001; } System.out.printf("%.2fn", ans); }}

2、C/C++组

#include <bits/stdc++.h>using namespace std;const double eps = 1e-6;const int inf = 0x3f3f3f3f;double xa, ya, xb, yb, L, A, ans;double x[6], y[6], Y[6];double dist(double a, double b, double c, double d){    return sqrt((c - a) * (c - a) + (d - b) * (d - b));}double get(double now, int pos1, int pos2){    if(fabs(x[pos1] - x[pos2]) <= eps && fabs(x[pos1] - now) <= eps) return inf;    if(now <= min(x[pos1], x[pos2]) || now >= max(x[pos1], x[pos2])) return inf;    return (y[pos2] - y[pos1]) / (x[pos2] - x[pos1]) * (now - x[pos2]) + y[pos2];}bool ok1(double now){    double xx = (xa + xb) / 2, yy = (ya + yb) / 2;    double a = L / 2 , c = dist(xa, ya, xb, yb) / 2;    double b = sqrt(a * a - c * c);    double mid = 1.0 - (now - xx) * (now - xx) / (a * a);    if(mid <= 0) return false;    mid = sqrt(mid) * b;    Y[1] = yy - mid, Y[2] = yy + mid;    return true;}bool ok2(double now){    int cnt = 2;    for(int i = 1; i <= 3; i++){        int nex = i + 1 == 4 ? 1 : i + 1;        double mid = get(now, i, nex);        if(mid - 1000 > eps) continue;        if(cnt == 3 && fabs(mid - Y[cnt]) <= eps) continue;        Y[++cnt] = mid;    }    if(cnt != 4) return false;    return true;}double get_angle(double a, double b, double c, double d){    double now = acos((c - a) / dist(a, b, c, d));    if(d - b < 0) return 2 * acos(-1) - now;    return now;}void init(){    A = get_angle(xa , ya , xb , yb);    double dis1 = dist(0, 0, xa, ya), dis2 = dist(0, 0, xb, yb);    double S1 = get_angle(0, 0, xa, ya) - A, S2 = get_angle(0, 0, xb, yb) - A;    xa = dis1 * cos(S1) , ya = dis1 * sin(S1);    xb = dis2 * cos(S2) , yb = dis2 * sin(S2);}void change(int pos){    double dis = dist(0, 0, x[pos], y[pos]);    double S = get_angle(0, 0, x[pos], y[pos]) - A;    x[pos] = dis * cos(S) , y[pos] = dis * sin(S);}double calc(double now){    if(!ok1(now)) return 0;    if(!ok2(now)) return 0;    double ma = max(min(Y[1], Y[2]), min(Y[3], Y[4]));    double mi = min(max(Y[1], Y[2]), max(Y[3], Y[4]));    if(mi - ma <= eps) return 0;    return mi - ma;}signed main(){    ios::sync_with_stdio(false);    cin.tie(0) , cout.tie(0);    cin >> xa >> ya >> xb >> yb >> L;    init();    for (int i = 1 ; i <= 3 ; i ++) cin >> x[i] >> y[i] , change(i);    if(L <= eps || dist(xa, ya, xb, yb) >= L) return cout << "0.00n" , 0;    for(double i = -1000 ; i <= 1000 ; i += 0.001) ans += calc(i) * 0.001;    cout << setprecision(2) << fixed << ans << 'n';    return 0;}


今日的「每日一题」就结束啦~

备战第 14 届蓝桥杯的小伙伴,快来一起刷题吧~
【每日一题】蓝桥杯历年真题题解 -荒岛探测
⬆️加入蓝桥杯备赛刷题⬆️

原文始发于微信公众号(蓝桥云课精选):【每日一题】蓝桥杯历年真题题解 -荒岛探测

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2023年2月16日19:25:49
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   【每日一题】蓝桥杯历年真题题解 -荒岛探测http://cn-sec.com/archives/1555888.html

发表评论

匿名网友 填写信息