博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces Round #242 (Div. 2) B. Megacity
阅读量:5778 次
发布时间:2019-06-18

本文共 2402 字,大约阅读时间需要 8 分钟。

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 test(s)
Input
4 9999981 1 12 2 13 3 12 -2 1
Output
2.8284271
Input
4 9999981 1 22 2 13 3 12 -2 1
Output
1.4142136
Input
2 11 1 9999972 2 1
Output
-1
题意:n个城市。每一个城市有坐标和人口。求以远点为圆心的最小的圆使得人口总数达到上限

思路:贪心

#include 
#include
#include
#include
#include
#include
using namespace std;const int maxn = 1010;const int inf = 1e6;map
mp;double dis(int x, int y) { return sqrt(x*x+y*y);}int main() { int n, s, x, y, k; scanf("%d%d", &n, &s); for (int i = 0; i < n; i++) { scanf("%d%d%d", &x, &y, &k); mp[dis(x, y)] += k; } map
::iterator it; double ans = -1; for (it = mp.begin(); it != mp.end(); it++) { if (s >= inf) break; s += it->second; ans = it->first; } if (s < inf) printf("-1\n"); else printf("%.7lf\n", ans);}

转载地址:http://pokyx.baihongyu.com/

你可能感兴趣的文章
基于jQuery带标题的图片3D切换焦点图
查看>>
杂题_POJ上的过桥问题
查看>>
C#AutoResetEvent和ManualResetEvent的区别
查看>>
[转]A plain english introduction to cap theorem
查看>>
C++11中的Lambda表达式
查看>>
从源代码上分析ListView的addHeaderView和setAdapter的调用顺序
查看>>
带节假日JS万年历控件代码
查看>>
美国地名大全(美国城市名称英文、中文)
查看>>
怎样在Linux下通过ldapsearch查询活动文件夹的内容
查看>>
常用的排序算法的时间复杂度和空间复杂度
查看>>
Samsung_tiny4412(驱动笔记09)----alloc_pages,kmalloc,vmalloc,kmem_cache,class
查看>>
PAT 1006. Sign In and Sign Out
查看>>
各大招聘网站信息实时查询浏览
查看>>
一次正确选择,改变一生命运!
查看>>
Java的内存泄漏
查看>>
c++ 队列
查看>>
PHP 设计模式 笔记与总结(8)策略模式
查看>>
.NET中使用Memcached的相关资源整理
查看>>
nyoj 1129 Salvation
查看>>
服务器无法通过系统非页面共享区来进行分配,因为共享区当前是空的
查看>>