题目描述:

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 (xiyi) 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.

题意:

题目中一个叫特斯拉的城市想要合并一些城市使得该城市变为特大城市 而成为特大城市的条件就是满足人口达到1000000人 首先特斯拉城市位于(0,0)这个坐标        题目会给一个n和m 其中n代表有n个城市 后面跟随n行,其中每一行都会有一个 x y sum 分别代表 (x,y)坐标 和 该城市的人口数sum; m代表特斯拉城市已经有m个人了 要求合并完这些城市到特大城市的的最小半径是多少

#include<bits/stdc++.h>
using namespace std;
const int maxn=1e3+100;
const double mod=1e-7;
int n,m;
struct add{double x,y,sum;
}s[maxn];
double check(double l,double r){double mid;while(r-l>=mod){mid=(l+r)/2;int sum=m;for(int i=0;i<n;i++){if(s[i].x*s[i].x+s[i].y*s[i].y<=mid*mid){sum+=s[i].sum;}}if(sum>=1000000){r=mid;}else{l=mid;}}return mid;
}
int main(){cin>>n>>m;int ans=m;for(int i=0;i<n;i++){cin>>s[i].x>>s[i].y>>s[i].sum;ans+=s[i].sum;}if(ans<1000000){cout<<"-1"<<endl;}else{printf("%.7lf\n",check(0,1000000000));}return 0;
}

Megacity(二分答案简单题之杨氏代码)相关推荐

  1. 二分答案二题-P1182数列分段II,P1873砍树

    T1:P1182T1:P1182T1:P1182 数列分段SectionIISectionIISection II 评测记录:https://www.luogu.org/recordnew/lists ...

  2. 简单题 6 清点代码库 (25 分)

    链接::题目详情 - L2-039 清点代码库 (25 分) (pintia.cn) 上图转自新浪微博:"阿里代码库有几亿行代码,但其中有很多功能重复的代码,比如单单快排就被重写了几百遍.请 ...

  3. 《二分答案》—— P1873 [COCI 2011/2012 #5] EKO / 砍树

    [COCI 2011/2012 #5] EKO / 砍树 题目描述 伐木工人 Mirko 需要砍 M M M 米长的木材.对 Mirko 来说这是很简单的工作,因为他有一个漂亮的新伐木机,可以如野火一 ...

  4. 2018.12.08 codeforces 939E. Maximize!(二分答案)

    传送门 二分答案好题. 题意简述:要求支持动态在一个数列队尾加入一个新的数(保证数列单增),查询所有子数列的 最大值减平均值 的最大值. 然而网上一堆高人是用三分做的. 我们先考虑当前的答案有可能由什 ...

  5. poj 1064 java_poj 1064(二分答案)

    题意: 有N条绳子,长度分别为 length[1,2,3,........,N]. 如果从它们中切割出K条长度相同的绳子,这K条绳子每条最长有多长? 结果保留两位小数. 题解: 二分可能的长度. AC ...

  6. Luogu P2920 时间管理【二分答案】

    二分答案水题. (像我这么蒻的人都能十几分钟A掉) https://www.luogu.org/problemnew/show/P2920 开始时间一定在从0到min(t[i]-s[i])的一段区间上 ...

  7. P4343-[SHOI2015]自动刷题机【二分答案】

    正题 题目链接:https://www.luogu.org/problem/P4343 题目大意 nnn个操作每个操作加几行代码或减几行代码,若代码积累到xxx行就自动删除所有代码并切掉一道题. 已知 ...

  8. PythonJava版【LeetCode】简单题答案整理01

    不得不开始刷LeetCode了,为了使小白的自尊心不受到毁灭性的打击,所以打算从最简单的题开始刷.现把所有题目的Python和Java代码都放在这儿,以便随时回忆.分两种语言的原因在于,Python是 ...

  9. P4343 [SHOI2015]自动刷题机 Python(二分答案)

    在这吐槽一下洛谷的OJ,对Python不是很友好,一样的思路实现下来大部分数据会TLE,需要不断的优化复杂度  :( 题目地址:[SHOI2015]自动刷题机 - 洛谷 优化不下去了,对比了一下Pyt ...

最新文章

  1. 【Android】Android中WIFI开发总结(一)
  2. 我从#100DaysOfCode中学到的东西
  3. vue实现页面权限显示_Vue 实现前端权限控制
  4. C#隐式类型和显示类型
  5. 【node】-----简单介绍 nodejs
  6. 如何在Scala中使用条件表达式
  7. Android Cursor浅析
  8. 反恐精英online单机版有各种武器
  9. win10 clion msvc opencv4.10 报错Process finished with exit code -1073741515 (0xC0000135)
  10. html table相同值合并单元格,ElementUI表格列相同值自动合并单元格( 单列 )
  11. 机器学习课堂笔记-作业二基本实现思路
  12. 关于C++ 里struct 和 class的区别
  13. GeoTrans2.4.1 用户手册 之 (三)协调转换和数据传输
  14. 学习OpCode前言
  15. 半导体术语的中英文版本
  16. 用c语言交通信号灯论文,plc交通信号灯毕业论文.doc
  17. 合泰单片机做电压表_合泰单片机使用总结
  18. 前端经典题目——使用 Promise 实现红绿灯交替重复亮
  19. html5腾讯地图自动定位,移动web端使用腾讯地图实现定位功能
  20. 能攻心则反侧自消,从古知兵非好战;不审势即宽严皆误,后来治蜀要深思

热门文章

  1. 【openpyxl的使用】操作excel
  2. 爸爸不在家,你要保护妈妈
  3. 轮胎翻新硫化机液压系统比例阀放大器
  4. python args_【Python】*args 和 **kwargs的用法
  5. 华科计算机学院和网安学院区别,华科网络安全和武大网络安全到一起,国家网安学院迎来首批学子入学...
  6. 清新卡通手绘PPT模板
  7. 在公共场所提供给用户使用的多媒体计算机,计算机一级填空-重点
  8. 超级简单的Android控件View转图片Bitmap
  9. 全球及中国透析器膜行业市场竞争与投资战略规划研究报告2022-2028年
  10. SAP监视系统CCMS