UVALive - 3635 - Pie(二分)

來源:互聯網
上載者:User

標籤:out   signed   nbsp   mat   cstring   ios   pre   pac   sig   

題意:有F + 1(1 <= F <= 10000)個人分N(1 <= N <= 10000)個圓形派,每個人得到的派面積相同,且必須是一整塊(不能夠兩個甚至多個派拼在一起),求每個人最多能得到多大面積的派。(誤差最多到0.001)

因為答案是小數類型的,並且N高達10000,故不可暴力枚舉。

可以二分枚舉最大面積,然後檢查是否切出來派的總個數大於等於F + 1。

(判相等時不可直接判相等,需要加精度控制)

 

#include<cstdio>  #include<cstring>  #include<cctype>  #include<cstdlib>  #include<cmath>  #include<iostream>  #include<sstream>  #include<iterator>  #include<algorithm>  #include<string>  #include<vector>  #include<set>  #include<map>  #include<deque>  #include<queue>  #include<stack>  #include<list>  #define fin freopen("in.txt", "r", stdin)  #define fout freopen("out.txt", "w", stdout)  #define pr(x) cout << #x << " : " << x << "   "  #define prln(x) cout << #x << " : " << x << endl  typedef long long ll;  typedef unsigned long long llu;  const int INT_INF = 0x3f3f3f3f;  const int INT_M_INF = 0x7f7f7f7f;  const ll LL_INF = 0x3f3f3f3f3f3f3f3f;  const ll LL_M_INF = 0x7f7f7f7f7f7f7f7f;  const double pi = acos(-1.0);  const double EPS = 1e-6;  const int dx[] = {0, 0, -1, 1};  const int dy[] = {-1, 1, 0, 0};  const ll MOD = 1e9 + 7;  const int MAXN = 100 + 10;  const int MAXT = 10000 + 10;  using namespace std;    int T, n, f;  double a[MAXT];    bool judge(double area){      int sum = 0;      for(int i = 0; i < n; ++i)  sum += int(a[i] / area);      return sum >= f;  }    int main(){      scanf("%d", &T);      while(T--){          scanf("%d%d", &n, &f);          for(int i = 0; i < n; ++i){              scanf("%lf", a + i);              a[i] = a[i] * a[i] * pi;          }          ++f;          double l = 0.0, r = *max_element(a, a + n);          while(l + EPS < r){              double mid = (l + r) / 2;              if(judge(mid))  l = mid;              else  r = mid;          }          printf("%.4lf\n", l);      }      return 0;  }  

 

UVALive - 3635 - Pie(二分)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.