Codeforces 424 B Megacity【贪心】
2015-04-16 21:11
281 查看
题意:给出城市(0,0),给出n个坐标,起始人数s,每个坐标k个人, 每个坐标可以覆盖到半径为r的区域,r=sqrt(x*x+y*y)的区域,问最小的半径是多少,使得城市的总人数大于等于1000000
最开始是排序,贪心来做的,发现sqrt的精度老达不到要求,于是翻了代码
于是发现用map就可以解决了
map<int,int>,it->first是第一个int的内容,it->second是第二个int的内容
话说本来是按照标签来找的,想做二分查找的题目的= =
View Code
最开始是排序,贪心来做的,发现sqrt的精度老达不到要求,于是翻了代码
于是发现用map就可以解决了
map<int,int>,it->first是第一个int的内容,it->second是第二个int的内容
话说本来是按照标签来找的,想做二分查找的题目的= =
#include<iostream> #include<cstdio> #include<cstring> #include <cmath> #include<stack> #include<vector> #include<map> #include<set> #include<queue> #include<algorithm> using namespace std; typedef long long LL; const int INF = (1<<30)-1; const int mod=1000000007; const int maxn=100005; int main(){ int n,s; map<int,int> cnt; scanf("%d %d",&n,&s); int x,y,k; for(int i=1;i<=n;i++){ cin>>x>>y>>k; cnt[x*x+y*y]+=k; } for(map<int,int>::iterator it=cnt.begin();it!=cnt.end();++it){ s+=it->second; if(s>=1000000){ printf("%lf\n",sqrt(it->first)); return 0; } } printf("-1\n"); return 0; }
View Code
相关文章推荐
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem D (Codeforces 831D) - 贪心 - 二分答案 - 动态规划
- CodeForces 721D. Maxim and Array(贪心,思维题)
- codeforces - 337c Quiz【贪心】
- codeforces 490E Restoring Increasing Sequence(贪心)
- Codeforces 797C Minimal String 贪心+模拟
- codeforces 725D Conteset Balloons 贪心
- Codeforces 390B Inna, Dima and Song(贪心)
- CodeForces - 344E Read Time && CodeForces - 830A Office Keys 二分+贪心
- Codeforces 394C Dominoes(贪心)
- Codeforces 651A Joysticks【贪心】
- [codeforces] B - Anatoly and Cockroaches 贪心
- codeforces 486C Palindrome Transformation(贪心)
- CodeForces 489B BerSU Ball (贪心)
- Codeforces 733D Kostya the Sculptor 贪心
- CodeForces 629BFar Relative’s Problem(贪心)
- Codeforces 191B(贪心)
- Codeforces 389C Fox and Box Accumulation【贪心】
- CodeForces 556A Case of the Zeros and Ones 【贪心 字符串】
- Codeforces 825D 二分贪心
- codeforces 285C Building Permutation (简单贪心)