uvalive 3635 Pie

解题思路:二分

  1 /**************************************************************************
  2 user_id: SCNU20102200088
  3 problem_id: uvalive 3635
  4 problem_name: Pie
  5 **************************************************************************/
  6 
  7 #include <algorithm>
  8 #include <iostream>
  9 #include <iterator>
 10 #include <iomanip>
 11 #include <sstream>
 12 #include <fstream>
 13 #include <cstring>
 14 #include <cstdlib>
 15 #include <climits>
 16 #include <bitset>
 17 #include <string>
 18 #include <vector>
 19 #include <cstdio>
 20 #include <cctype>
 21 #include <ctime>
 22 #include <cmath>
 23 #include <queue>
 24 #include <stack>
 25 #include <list>
 26 #include <set>
 27 #include <map>
 28 using namespace std;
 29 
 30 //线段树
 31 #define lson l,m,rt<<1
 32 #define rson m+1,r,rt<<1|1
 33 
 34 //手工扩展栈
 35 #pragma comment(linker,"/STACK:102400000,102400000")
 36 
 37 const double EPS=1e-5;
 38 const double PI=acos(-1.0);
 39 const double E=2.7182818284590452353602874713526;  //自然对数底数
 40 const double R=0.5772156649015328606065120900824;  //欧拉常数:(1+1/2+...+1/n)-ln(n)
 41 
 42 const int x4[]={-1,0,1,0};
 43 const int y4[]={0,1,0,-1};
 44 const int x8[]={-1,-1,0,1,1,1,0,-1};
 45 const int y8[]={0,1,1,1,0,-1,-1,-1};
 46 
 47 typedef long long LL;
 48 
 49 typedef int T;
 50 T max(T a,T b){ return a>b? a:b; }
 51 T min(T a,T b){ return a<b? a:b; }
 52 T gcd(T a,T b){ return b==0? a:gcd(b,a%b); }
 53 T lcm(T a,T b){ return a/gcd(a,b)*b; }
 54 
 55 ///////////////////////////////////////////////////////////////////////////
 56 //Add Code:
 57 int n,f,r[10005];
 58 double s[10005];
 59 
 60 int cal(double x){
 61     int ret=0;
 62     for(int i=1;i<=n;i++) ret+=floor(s[i]/x);
 63     return ret;
 64 }
 65 
 66 double erfen(){
 67     double l=0,r=1e9;
 68     while(r-l>EPS){
 69         double m=(l+r)/2;
 70         if(f+1<=cal(m)) l=m;
 71         else r=m;
 72     }
 73     return l;
 74 }
 75 ///////////////////////////////////////////////////////////////////////////
 76 
 77 int main(){
 78     std::ios::sync_with_stdio(false);
 79     //freopen("in.txt","r",stdin);
 80     //freopen("out.txt","w",stdout);
 81     ///////////////////////////////////////////////////////////////////////
 82     //Add Code:
 83     int Case,i;
 84     scanf("%d",&Case);
 85     while(Case--){
 86         scanf("%d%d",&n,&f);
 87         for(i=1;i<=n;i++){
 88             scanf("%d",&r[i]);
 89             s[i]=PI*r[i]*r[i];
 90         }
 91         double ans=erfen();
 92         printf("%.4lf\n",ans);
 93     }
 94     ///////////////////////////////////////////////////////////////////////
 95     return 0;
 96 }
 97 
 98 /**************************************************************************
 99 Testcase:
100 Input:
101 3
102 3 3
103 4 3 3
104 1 24
105 5
106 10 5
107 1 4 2 3 4 5 6 5 4 2
108 Output:
109 25.1327
110 3.1416
111 50.2655
112 **************************************************************************/

posted on 2013-09-27 13:47  SCNU20102200088  阅读(212)  评论(0编辑  收藏  举报

导航