首页 > 其他 > 详细

Codeforces 424 B Megacity【贪心】

时间:2015-04-16 23:08:57      阅读:295      评论:0      收藏:0      [点我收藏+]

题意:给出城市(0,0),给出n个坐标,起始人数s,每个坐标k个人, 每个坐标可以覆盖到半径为r的区域,r=sqrt(x*x+y*y)的区域,问最小的半径是多少,使得城市的总人数大于等于1000000

最开始是排序,贪心来做的,发现sqrt的精度老达不到要求,于是翻了代码

于是发现用map就可以解决了

map<int,int>,it->first是第一个int的内容,it->second是第二个int的内容

话说本来是按照标签来找的,想做二分查找的题目的= =

技术分享
 1 #include<iostream>  
 2 #include<cstdio>  
 3 #include<cstring> 
 4 #include <cmath> 
 5 #include<stack>
 6 #include<vector>
 7 #include<map> 
 8 #include<set>
 9 #include<queue> 
10 #include<algorithm>  
11 using namespace std;
12 
13 typedef long long LL;
14 const int INF = (1<<30)-1;
15 const int mod=1000000007;
16 const int maxn=100005;
17 
18 int main(){
19     int n,s;
20     map<int,int> cnt;
21     scanf("%d %d",&n,&s);
22     int x,y,k;
23     for(int i=1;i<=n;i++){
24         cin>>x>>y>>k;
25         cnt[x*x+y*y]+=k;
26     }
27     
28     for(map<int,int>::iterator it=cnt.begin();it!=cnt.end();++it){
29         s+=it->second;
30         if(s>=1000000){
31             printf("%lf\n",sqrt(it->first));
32             return 0;
33         }
34     }
35     printf("-1\n");
36     return 0;
37 }
View Code

 

Codeforces 424 B Megacity【贪心】

原文:http://www.cnblogs.com/wuyuewoniu/p/4433300.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!