题解 | 圆覆盖

圆覆盖

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

#include <bits/stdc++.h>
using namespace std;

const int N=1e5+5;
struct node{
    double d;
    int v;
};

node a[N];
bool cmp(node a,node b){
    return a.d<b.d;
}

int main() {
    long long n,s;cin>>n>>s;
    for(int i=0;i<n;i++){
        long long x,y,v;
        cin>>x>>y>>v;
        a[i].d=sqrt(x*x+y*y);
        a[i].v=v;
    }
    sort(a,a+n,cmp);

    long long sum=0;
    for (int i = 0; i < n; i++) {
        sum += a[i].v;
        if (sum >= s) {
            printf("%.6lf",a[i].d);
            return 0;
        }
    }
    cout<<-1;
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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