Uva 派 (Pie,NWERC 2006,LA 3635)

依然是一道二分查找

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cmath>
 4 using namespace std;
 5
 6 const double PI=acos(-1.0);
 7 int N,F;
 8 double r[10001];
 9
10 bool ok(double area)
11 {
12     int sum=0;
13     for(int i=0;i<N;i++)
14         sum+=floor(r[i]/area);
15     return sum>=F+1;
16 }
17
18 int main()
19 {
20     int T;
21     cin>>T;
22     while(T--)
23     {
24         cin>>N>>F;
25         double maxn=-1;
26         for(int i=0;i<N;i++)
27         {
28             int a;
29             cin>>a;
30             r[i]=PI*a*a;
31             maxn=max(maxn,r[i]);
32         }
33         double L=0,R=maxn;
34         while(R-L>1e-4)
35         {
36             double M=(L+R)/2;
37             if(ok(M)) L=M;else R=M;
38         }
39         printf("%.4lf\n",L);
40     }
41     return 0;
42 }
时间: 2024-08-06 15:38:04

Uva 派 (Pie,NWERC 2006,LA 3635)的相关文章

uva 12097 Pie(二分搜索)

uva 12097 Pie My birthday is coming up and traditionally I'm serving pie. Not just one pie, no, I have a number N of them, of various tastes and of various sizes. F of my friends are coming to my party and each of them gets a piece of pie. This shoul

集合栈计算机(The Set Stack Computer,ACM/ICPC NWERC 2006,UVa12096)

集合栈计算机(The Set Stack Computer,ACM/ICPC NWERC 2006,UVa12096) 对于集合的集合,很难直接表示,因此,为方便起见,为每个不同的集合分配一个不同的ID,每个集合都可以表示成所含集合的ID集合,一个集合就可以表示为一个set 我的理解: {}:1 {{}} 2 栈中的都是集合,所以也是int类型的 实际进行操作的过程中,可以用map将每种集合和对应的ID关联起来,这样做既可以完成查找ID的任务,还可以同时判定是否出现了新的集合. 用vector作

LA 3635 - Pie 【二分】

Regionals 2006 >> Europe - Northwestern 3635 - Pie Time limit: 3.000 seconds My birthday is coming up and traditionally I'm serving pie. Not just one pie, no, I have a number N of them, of various tastes and of various sizes. F of my friends are com

LA 3635 派

题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1636 题意: f+1个人,来分 n 个圆形派,每个人只能从一个派中拿,也就是说,不能从两个里面去拼. 求每个人最大的面积. 分析: 二分. 二分能够得到的最大面积x,怎么判断是否可以分到呢? 把每一个派分成 x,有多少份>=f+1,即可: 1 #include

LA 3635 Pie

二分答案 找到最大的圆的面积作为每个人可能分到的最大的面积. 对每个人可能分到的面积二分 验算时,求出每个pie可以切出的最大块数,然后总的块数和需要的块数比较 PS:(就是精度恶心) #include <map> #include <cmath> #include <cstdio> #include <vector> #include <string> #include <cstring> #include <algorith

UVA 11636 Hello World,LA 3602 DNA Consensus String,UVA 10970 Big Chocolate,UVA 10340 All in All,UVA 11039 Building Designing

课程好紧啊,只能刷点水题了,几乎都是贪心. UVA 11636 Hello World 二的幂答案就是二进制长度减1,不是二的幂答案就是是二进制长度. #include<cstdio> int main() { int n,kas = 0; while(scanf("%d",&n),n>0){ int r = 0; for(n--;n;n>>=1) r++; printf("Case %d: %d\n",++kas,r); }

Uva 网络(Network,Seoul 2007,LA 3902)

1 #include<iostream> 2 #include<cstring> 3 #include<vector> 4 using namespace std; 5 6 const int maxn=1000+10; 7 int n,s,k; 8 vector<int> tree[maxn],nodes[maxn]; 9 int fa[maxn]; 10 bool covered[maxn]; 11 12 void dfs(int u,int f,int

打印队列 (Printer Queue,ACM/ICPC NWERC 2006,UVA12100)

题目描述: 题目思路: 使用一个队列记录数字,一个优先队列记录优先级,如果相等即可打印: 1 #include <iostream> 2 #include <queue> 3 using namespace std; 4 int main(int argc, char *argv[]) 5 { 6 int t; 7 cin >> t; 8 while(t--) 9 { 10 int n,pos; 11 queue<int> q ; 12 priority_q

Nwerc 2006【escape】

描述 给出数字N(1<=N<=10000),X(1<=x<=1000),Y(1<=Y<=1000),代表有N个敌人分布一个X行Y列的矩阵上矩形的行号从0到X-1,列号从0到Y-1再给出四个数字x1,y1,x2,y2,代表你要从点(x1,y1)移到(x2,y2).在移动的过程中你当然希望离敌人的距离的最小值最大化,现在请求出这个值最大可以为多少,以及在这个前提下你最少要走多少步才可以回到目标点.注意这里距离的定义为两点的曼哈顿距离,即某两个点的坐标分为(a,b),(c,d