题解 | 圆覆盖 | 你知道 upper_bound(comp_) 参数怎么写吗

圆覆盖

https://www.nowcoder.com/practice/4f96afe5dfe74dad88dbe419d33f9536

虽然但是,用不着二分

#include <bits/stdc++.h>
using LL = long long;
using namespace std;
const int N = 1e5 + 5;
const double eps = 1e-7;

int n;
LL S;

struct Node{
    double R;
    LL v;
}p[N];

void solve() {
    cin >> n >> S; 
    for(int i = 1; i <= n; i++) {
        int x, y, v;
        cin >> x >> y >> v;
        p[i] = {sqrt((double) x * x + (double) y * y), v};
    }
    sort(p + 1, p + 1 + n, [](auto a, auto b) {
        return a.R < b.R;
    });
    for(int i = 1; i <= n; i++) {
       p[i].v += p[i - 1].v; 
    }
    // auto it = lower_bound(p + 1, p + 1 + n, S, [](auto a, auto b){
    //     return a.v < b;
    // });
    auto it = upper_bound(p + 1, p + 1 + n, S - 1, [](auto a, auto b){
        return a < b.v;
    });
    if(it == p + n + 1) {
        cout << -1 << "\n";
    } else {
        cout << it->R << "\n";
    }
}

int main() {
    cout << fixed << setprecision(12);
    cin.tie(0)->sync_with_stdio(0);
    int T = 1;
    // cin >> T;
    while (T--) solve();
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务