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\n",sqrt(it->first));
32             return 0;
33         }
34     }
35     printf("-1\n");
36     return 0;
37 }

时间: 2025-01-03 04:17:53

Codeforces 424 B Megacity【贪心】的相关文章

Codeforces 424 C Magic Formulas

Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 424C Description People in the Tomskaya region like magic formulas very much. You can see some of them below. Imagine you are given a sequ

Codeforces Round #300——C贪心——Tourist&#39;s Notes

Description A tourist hiked along the mountain range. The hike lasted for n days, during each day the tourist noted height above the sea level. On the i-th day height was equal to some integer hi. The tourist pick smooth enough route for his hike, me

Codeforces 77C 树形dp + 贪心

题目链接:点击打开链接 题意: 给定n个点, 每个点的豆子数量 下面是一棵树 再给出起点 每走到一个点,就会把那个点的豆子吃掉一颗. 问:回到起点最多能吃掉多少颗豆子 思路:树形dp 对于当前节点u,先把子节点v都走一次. 然后再往返于(u,v) 之间,直到u点没有豆子或者v点没有豆子. dp[u] 表示u点的最大值.a[u] 是u点剩下的豆子数. #include <cstdio> #include <vector> #include <algorithm> #inc

Codeforces 788A Functions again - 贪心

Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about

Codeforces 486C Palindrome Transformation(贪心)

题目链接:Codeforces 486C Palindrome Transformation 题目大意:给定一个字符串,长度N,指针位置P,问说最少花多少步将字符串变成回文串. 解题思路:其实只要是对称位置不相同的,那么指针肯定要先移动到这里,修改字符只需要考虑两种方向哪种更优即 可.然后将所有需要到达的位置跳出来,贪心处理. #include <cstdio> #include <cstring> #include <cstdlib> #include <vec

codeforces 735C Tennis Championship(贪心+递推)

Tennis Championship 题目链接:http://codeforces.com/problemset/problem/735/C --每天在线,欢迎留言谈论. 题目大意: 给你一个 n (2≤n≤10^18),代表一共有n位参加比赛的选手. 游戏规则: ①每次比赛,输的选手将离开赛场 ②相互比赛的选手 他们的获胜的次数相差不能超过1(获胜4次的选手只能跟3或5次的选手比赛) 问题:最终赢得比赛的选手,胜场最多能为多少. 思路: 贪心:①选一名选手让他一直获胜且优先让他参加比赛 ②当

CodeForces 545C Woodcutters (贪心orDP)

[题目链接]:click here~~ [题目大意]: 有n棵树,给出每棵树的位置和高度,然后把树砍掉,树可以向左倒也可以向右倒.输出最多能砍几棵树. [思路]:利用贪心的思想.第一棵树的左边和最后一棵树的右边没树,所以他们向两边倒,然后对于中间的树来说,首先先向左边倒,然后左边距离如果不够的话再向右边倒,向右倒的时候注意更新一下距离. 代码: /* * Problem: CodeForces 545C * Running time: 46MS * Complier: G++ * Author:

Codeforces 700B Connecting Universities - 贪心

Treeland is a country in which there are n towns connected by n - 1 two-way road such that it's possible to get from any town to any other town. In Treeland there are 2k universities which are located in different towns. Recently, the president signe

Codeforces 1154D - Walking Robot - [贪心]

题目链接:https://codeforces.com/contest/1154/problem/D 题解: 贪心思路,没有太阳的时候,优先用可充电电池走,万不得已才用普通电池走.有太阳的时候,如果可充电电池能够充一格电,就用普通电池跑(让可充电池充电),否则就用可充电电池走. AC代码: #include<bits/stdc++.h> using namespace std; const int maxn=2e5+10; int n,a,b; bool s[maxn]; int main()