zoukankan      html  css  js  c++  java
  • Codeforces 424 B Megacity【贪心】

    题意:给出城市(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
    ",sqrt(it->first));
    32             return 0;
    33         }
    34     }
    35     printf("-1
    ");
    36     return 0;
    37 }
    View Code
  • 相关阅读:
    JavaWeb WebBrowserTool KernelEngine
    类模板 C++快速入门45
    动态数组的使用
    动态数组的使用
    鱼C小甲鱼
    栈原理演示
    鱼C小甲鱼
    类模板 C++快速入门45
    delphi实例
    栈原理演示
  • 原文地址:https://www.cnblogs.com/wuyuewoniu/p/4433300.html
Copyright © 2011-2022 走看看