Codeforces Round #242 (Div. 2) B. Megacity

来源:互联网 发布:淘宝靠谱的三星手机店 编辑:程序博客网 时间:2024/05/17 22:58

思路:对于所有给定点算出到原点的距离,然后排序,采用贪心思想,从小到大的扩充人数,直至到达one million

#include <stdio.h>#include <iostream>#include <string>#include <string.h>#include <algorithm>#include <stdlib.h>#include <math.h>#include <vector>#include <map>using namespace std;const int maxn = 1000000;map<double, int>mp;double dist(int x,int y){    if(x < 0)        x = -x;    if(y < 0)        y = -y;    return sqrt(x*x + y*y);}int main(){    int n,s;    while(~scanf("%d%d",&n,&s)){        int x,y,k;        for(int i = 0;i < n;i++){            scanf("%d%d%d",&x,&y,&k);            mp[dist(x, y)] += k;        }        map<double, int>::iterator it;        double ans = -1;        for(it = mp.begin();it != mp.end();it++){            if(s >= maxn)                break;            s += it->second;            ans = it->first;            //printf("%.7lf   %d\n",it->first,it->second);        }        if(s < maxn)            printf("-1\n");        else            printf("%.7lf\n",ans);    }    return 0;}


0 0