题目描述:
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.
输入描述:
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).
输出描述:
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.
输入:
4 999998
1 1 1
2 2 1
3 3 1
2 -2 1
4 999998
1 1 2
2 2 1
3 3 1
2 -2 1
2 1
1 1 999997
2 2 1
输出:
2.8284271
1.4142136
-1
题意:
给出城市(0,0),给出n个坐标,起始人数s,每个坐标k个人, 每个坐标可以覆盖到半径为r的区域,r=sqrt(xx+yy)的区域,问最小的半径是多少,使得城市的总人数大于等于1000000
题解
排序,贪心来做
代码:

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;const int maxn = 10000 + 5;
struct point{int k;double r;
};
int n,s;
point a[maxn];int cmp(point x,point y){return x.r < y.r;
}int main(){int x,y;while(scanf("%d%d",&n,&s)!=EOF){int sum = s;for(int i = 0; i < n; i ++){scanf("%d%d%d",&x,&y,&a[i].k);a[i].r = sqrt(x * x + y * y);}bool flag = false;double ans = 0;sort(a,a + n,cmp);for(int i = 0; i < n; i ++){sum += a[i].k;if(sum >= 1000000){flag = true;ans = a[i].r;break;}}if(!flag) printf("-1\n");else{printf("%.7lf\n",ans);}}return 0;
}

Codeforces--424B--Megacity相关推荐

  1. CodeForces 375D Tree and Queries

    传送门:https://codeforces.com/problemset/problem/375/D 题意: 给你一颗有根树,树上每个节点都有其对应的颜色,有m次询问,每次问你以点v为父节点的子树内 ...

  2. 「日常训练」Bad Luck Island(Codeforces Round 301 Div.2 D)

    题意与分析(CodeForces 540D) 是一道概率dp题. 不过我没把它当dp做... 我就是凭着概率的直觉写的,还好这题不算难. 这题的重点在于考虑概率:他们喜相逢的概率是多少?考虑超几何分布 ...

  3. 【codeforces 812C】Sagheer and Nubian Market

    [题目链接]:http://codeforces.com/contest/812/problem/C [题意] 给你n个物品; 你可以选购k个物品;则 每个物品有一个基础价值; 然后还有一个附加价值; ...

  4. CodeForces 获得数据

    针对程序的输出可以看见 CodeForces :当输入.输出超过一定字符,会隐藏内容 所以:分若干个程序进行输入数据的获取 1. 1 for (i=1;i<=q;i++) 2 { 3 scanf ...

  5. codeforces水题100道 第二十七题 Codeforces Round #172 (Div. 2) A. Word Capitalization (strings)...

    题目链接:http://www.codeforces.com/problemset/problem/281/A 题意:将一个英文字母的首字母变成大写,然后输出. C++代码: #include < ...

  6. CodeForces 595A

    题目链接: http://codeforces.com/problemset/problem/595/A 题意: 一栋楼,有n层,每层有m户,每户有2个窗户,问这栋楼还有多少户没有睡觉(只要一个窗户灯 ...

  7. codeforces A. Jeff and Digits 解题报告

    题目链接:http://codeforces.com/problemset/problem/352/A 题目意思:给定一个只有0或5组成的序列,你要重新编排这个序列(当然你可以不取尽这些数字),使得这 ...

  8. Codeforces Round #506 (Div. 3)

    Codeforces Round #506 (Div. 3) 实习期间事不多,对div3 面向题解和数据编程了一波 A. Many Equal Substrings 题目链接 A题就是找后缀和前缀重合 ...

  9. Codeforces Round #417:E. FountainsSagheer and Apple Tree(树上博弈)

    Codeforces Round #417:E. FountainsSagheer and Apple Tree(树上博弈) 标签: codeforces 2017-06-02 11:41 29人阅读 ...

  10. [题解]RGB Substring (hard version)-前缀和(codeforces 1196D2)

    题目链接:https://codeforces.com/problemset/problem/1196/D2 题意: q 个询问,每个查询将给你一个由 n 个字符组成的字符串s,每个字符都是 &quo ...

最新文章

  1. @所有人,不服来战!你都认不出的这些汉字,机器能识别吗?
  2. 反弹c语言作业,C语言实现反弹球小游戏
  3. python起步输入-《Python编程:从入门到实践》第一章:起步
  4. FastAPI使用async?乱用async导致灾难,不如直接不用
  5. 《系统集成项目管理工程师》必背100个知识点-43项目成本控制的主要内容
  6. linux服务器拷贝目录文件夹,linux两台服务器之间文件/文件夹拷贝
  7. postgresql主从备份_基于windows平台的postgresql主从数据库流备份配置
  8. iPad开发(Universal Applications)
  9. 【译】你不知道的 Chrome 调试工具技巧 第二十天:Workspace的黑魔法
  10. 我的HTML学习之路02
  11. 重温微积分 —— 偏微分与链式法则
  12. Java学习之JDBC(1)
  13. Linux下更换jdk和配置环境变量
  14. linux下免密认证登录失败原因总结
  15. 数据库-创建数据库-创建数据表
  16. Visio安装失败问题解决
  17. 干货 | 携程度假数据治理之数据标准管理实践
  18. 编译原理学习笔记 6.4 分程序结构语言的符号表组织
  19. 用后台开发的逻辑理念学习VUE
  20. 计算机土木工程专业,土木工程专业需要什么样的电脑配置?

热门文章

  1. 自动上料码垛机 夹钳机器人 全自动电气检查机 自动脱鸡毛机大理石切割机 桌面数控机床 塑料链板输送机 金属板成型机 机械臂喷嘴 手机自动抛光机…设计
  2. sqlalchemy表关系之多对多
  3. 螺旋天线有方向性吗_什么是四臂螺旋天线?有何优点?
  4. 英语记忆软件测试大乐,‎App Store 上的“学习土耳其词汇 - 学英语法游戏单词汇记忆卡片小测试练习”...
  5. 汇编语言:简单的英文字母大小写转换
  6. costmap的膨胀参数解读--转载
  7. 时敏目标简介___未整理
  8. 打印服务器共享打印维护
  9. 常用input输入限制数字,汉字,英文字母等
  10. 【人工智能】人工智能和双曲几何