CodeForces - 424B (贪心算法)
Time Limit: 2000MS | Memory Limit: 262144KB | 64bit IO Format: %I64d & %I64u |
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[];
bool cmp(sa x,sa y)
{
return x.r<y.r;
}
int main()
{
int i,n,s,a,b;
cin>>n>>s;
for(i=;i<n;i++)
{
cin>>a>>b>>data[i].k;
data[i].r=sqrt(a*a+b*b);
}
sort(data,data+n,cmp);
for(i=;i<n;i++)
{
s+=data[i].k;
if(s>=)
{
printf("%.7lf",data[i].r);
return ;
}
}
cout<<-<<endl;
return ;
}
CodeForces - 424B (贪心算法)的更多相关文章
- 贪心算法(Greedy Algorithm)
参考: 五大常用算法之三:贪心算法 算法系列:贪心算法 贪心算法详解 从零开始学贪心算法 一.基本概念: 所谓贪心算法是指,在对问题求解时,总是做出在当前看来是最好的选择.也就是说,不从整体最优上加以 ...
- 算法导论----贪心算法,删除k个数,使剩下的数字最小
先贴问题: 1个n位正整数a,删去其中的k位,得到一个新的正整数b,设计一个贪心算法,对给定的a和k得到最小的b: 一.我的想法:先看例子:a=5476579228:去掉4位,则位数n=10,k=4, ...
- LEETCODE —— Best Time to Buy and Sell Stock II [贪心算法]
Best Time to Buy and Sell Stock II Say you have an array for which the ith element is the price of a ...
- ACM_ICPC hdu-2111(简单贪心算法)
一道非常简单的贪心算法,但是要注意输入的价值是单位体积的价值,并不是这个物品的总价值!#include <iostream> #include <stdio.h> #inclu ...
- 基于贪心算法的几类区间覆盖问题 nyoj 12喷水装置(二) nyoj 14会场安排问题
1)区间完全覆盖问题 问题描述:给定一个长度为m的区间,再给出n条线段的起点和终点(注意这里是闭区间),求最少使用多少条线段可以将整个区间完全覆盖 样例: 区间长度8,可选的覆盖线段[2,6],[1, ...
- 增强学习贪心算法与Softmax算法
(一) 这个算法是基于一个概率来对探索和利用进行折中:每次尝试时,以概率进行探索,即以均匀概率随机选取一个摇臂,以的概率进行利用,即以这个概率选择当前平均奖赏最高的摇臂(如有多个,则随机选取). 其中 ...
- 【九度OJ】题目1434贪心算法
题目 本题的贪心算法策略需要深入思考一下 看到题目,最初没有理解题目的要求:看尽量多的完整的节目.尽量多是指数量多,自己理解成观看的时间最长.这样想其实简化了这道题. 正确理解题意后,首先想到的想法是 ...
- 题目1437:To Fill or Not to Fill:贪心算法解决加油站选择问题(未解决)
//贪心算法解决加油站选择问题 //# include<iostream> # include<stdio.h> using namespace std; # include& ...
- 贪心算法(Greedy Algorithm)之最小生成树 克鲁斯卡尔算法(Kruskal's algorithm)
克鲁斯卡尔算法(Kruskal's algorithm)是两个经典的最小生成树算法的较为简单理解的一个.这里面充分体现了贪心算法的精髓.大致的流程能够用一个图来表示.这里的图的选择借用了Wikiped ...
随机推荐
- codevs3196 黄金宝藏
题目描述 Description 小毛终于到达宝藏点,他意外地发现有一个外星人(名叫Pluto).宝藏是一些太空黄金,有n堆排成一行,每堆中有xi颗黄金.小毛和Pluto决定轮流从中取出黄金,规则是每 ...
- Android基础类之BaseAdapter
转:http://www.cnblogs.com/mandroid/archive/2011/04/05/2005525.html Android基础类之BaseAdapter BaseAdapter ...
- hdu acmsteps 2.1.3 Cake
Cake Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submissi ...
- threading使用心得
需求:监控多个重要网站(多线程),出现访问异常重试2次,第三次开始告警. 日志模块 import logging import logging.config # 日志配置 LOGCONF_FILENA ...
- 栈的的顺序实例SeqStack实现
1.#include <stdio.h>#include <stdlib.h>#include "SeqStack.h"/* run this progra ...
- Json序列化对象
之前都是用的二进制的序列化方法,是.net自带的,但是最常用到的还是Json序列化 (1)只需要调用 Newtonsoft.Json.dll 即可 public class JsonTools { / ...
- 代码重构-2 简单不变的 if else 用字典代替
原代码 private string GetExDesc(string lotteryCode) { string exDesc = "抽奖"; if (lotteryCode.T ...
- PHP防止重复提交表单(helloweba网站经典实例)
<?php session_start(); header("Content-Type:text/html;charset:utf8"); function set_toke ...
- 转载大神的检测网站重定向的python脚本
#!/usr/bin/env python #coding=utf8 import sys import requests def check_for_redirects(url): try: r = ...
- 《JAVA与模式》之享元模式
<JAVA与模式>之享元模式 在阎宏博士的<JAVA与模式>一书中开头是这样描述享元(Flyweight)模式的: Flyweight在拳击比赛中指最轻量级,即“蝇量级”或“雨 ...