地雷阵

地雷阵

题目

image

示例

image

解题思路

  1. 根据每个坐标获取爆炸范围。
  2. 通过每个爆炸点判断爆炸角度范围。
  3. 最后将多个爆炸区间进行融合。
  4. 最后获取到不在爆炸区间范围的角度。

代码

#include <bits/stdc++.h>

using namespace std;

bool compValue(vector<double> a, vector<double> b){
    return a[0] < b[0];
}

int main(){
    int n;
    cin >> n;
    double Pi = acos(-1);
    vector<vector<double>> a(n, vector<double>(2, 0));
    for(int i = 0; i < n; i++){
        double x, y, r;
        cin >> x >> y >> r;
        a[i][0] = (atan(y/x) - asin(r/sqrt(x*x+y*y)))*180/Pi;
        a[i][1] = (atan(y/x) + asin(r/sqrt(x*x+y*y)))*180/Pi;
    }
    sort(a.begin(), a.end(), compValue);
    //区间整合
    double temp = 0;
    double lastroute = 0;
    for(int i = 0; i < n; i++){
        if(temp < a[i][0]){
            lastroute = lastroute + a[i][0]-temp;
            temp = a[i][1];
        }else if(temp >= a[i][0] && temp <= a[i][1]){
            temp = a[i][1];
        }else{
            continue;
        }
        //cout << a[i][0] << " " << a[i][1] <<" " <<lastroute<< endl;
    }
    if(temp < 90) lastroute = lastroute + 90 -temp;
    cout << fixed << setprecision(3) <<lastroute / 90 ;
    return 0;
}
posted @ 2026-03-31 15:16  heyuikn  阅读(2)  评论(0)    收藏  举报