CodeForces - 424B (贪心算法)
来源:互联网 发布:舞蹈培训网络推广方案 编辑:程序博客网 时间:2024/06/05 14:34
Description
The administration of the Tomsk Region firmly believes that it's time to become a megacity (that is, get population of one million). Instead of improving the demographic situation, they decided to achieve its goal by expanding the boundaries of the city.
The city of Tomsk can be represented as point on the plane with coordinates (0; 0). The city is surrounded with n other locations, the i-th one has coordinates (xi, yi) with the population of ki people. You can widen the city boundaries to a circle of radius r. In such case all locations inside the circle and on its border are included into the city.
Your goal is to write a program that will determine the minimum radius r, to which is necessary to expand the boundaries of Tomsk, so that it becomes a megacity.
Input
The first line of the input contains two integers n and s (1 ≤ n ≤ 103; 1 ≤ s < 106) — the number of locatons around Tomsk city and the population of the city. Then n lines follow. The i-th line contains three integers — the xi and yi coordinate values of the i-th location and the number ki of people in it (1 ≤ ki < 106). Each coordinate is an integer and doesn't exceed 104 in its absolute value.
It is guaranteed that no two locations are at the same point and no location is at point (0; 0).
Output
In the output, print "-1" (without the quotes), if Tomsk won't be able to become a megacity. Otherwise, in the first line print a single real number — the minimum radius of the circle that the city needs to expand to in order to become a megacity.
The answer is considered correct if the absolute or relative error don't exceed 10 - 6.
Sample Input
4 999998
1 1 1
2 2 1
3 3 1
2 -2 1
2.8284271
4 999998
1 1 2
2 2 1
3 3 1
2 -2 1
1.4142136
2 1
1 1 999997
2 2 1
-1
Source
#include <iostream>#include <stdio.h>#include <algorithm>#include <math.h>using namespace std;struct sa{ int k; double r;}data[10050];bool cmp(sa x,sa y){ return x.r<y.r;}int main(){ int i,n,s,a,b; cin>>n>>s; for(i=0;i<n;i++) { cin>>a>>b>>data[i].k; data[i].r=sqrt(a*a+b*b); } sort(data,data+n,cmp); for(i=0;i<n;i++) { s+=data[i].k; if(s>=1000000) { printf("%.7lf",data[i].r); return 0; } } cout<<-1<<endl; return 0;}
- CodeForces - 424B (贪心算法)
- codeforces 3B (贪心)
- codeforces 540B-贪心
- codeforces 604B (贪心)
- Codeforces 682B贪心
- CodeForces - 762B(贪心)
- 贪心-Codeforces 777B
- Codeforces 191B(贪心)
- Codeforces 700B 贪心
- CodeForces 4B Before an Exam(贪心算法)
- Codeforces 500B New Year Permutation Floyd算法+贪心
- codeforces 3B Lorry 贪心
- Codeforces 3B Lorry 贪心
- CodeForces 287B 二分贪心
- Codeforces 364B 背包+贪心
- CodeForceS#276-B(贪心)
- CodeForces 339B (贪心模拟)
- Codeforces 597B Restaurant 【贪心】
- CodeForces - 417E(随机数)
- CodeForces - 420A (字符对称问题)
- php多进程学习
- 辗转相除法的证明
- Codeforces 424A (思维题)
- CodeForces - 424B (贪心算法)
- 算法的重要性
- Codeforces 424C(异或)
- CodeForces - 426A(排序)
- CodeForces - 426B(对称图形)
- CodeForces - 427A (警察和罪犯 思维题)
- javascript 图片 懒加载、预加载
- CodeForces - 427B (模拟题)
- MyBatis之传入参数