码迷,mamicode.com
首页 > 其他好文 > 详细

BestCoder Round #55 1001 Pyramid Split

时间:2015-09-12 23:33:03      阅读:297      评论:0      收藏:0      [点我收藏+]

标签:

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5432

裸的二分查找,同时注意向下取整

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <algorithm>
 4 
 5 using namespace std;
 6 
 7 #define maxn 100000+5
 8 const double exps = 1e-6;
 9 
10 int t,n;
11 
12 struct node
13 {
14     double h,w;
15 }a[maxn];
16 
17 
18 int main()
19 {
20     scanf( "%d",&t );
21     while( t-- )
22     {
23         scanf( "%d",&n );
24         for( int i=0; i<n; i++ )
25             scanf( "%lf",&a[i].h );
26         for( int i=0; i<n; i++ )
27         {
28             scanf( "%lf",&a[i].w );
29         }
30         double L = 0, R = 1000, mid;
31         while( R - L > exps)
32             {
33             mid = (L + R) / 2;
34             double s, sum1 = 0, sum2 = 0;
35             for(int j = 0; j < n; j++)
36             {
37 
38                 if(a[j].h <= mid) s = 0;
39                 else s = a[j].w * a[j].w * (a[j].h- mid) * (a[j].h - mid) * (a[j].h - mid) / (3.0 * a[j].h * a[j].h);
40                 sum1 += s;
41                 sum2 += a[j].w * a[j].w * a[j].h / 3.0 - s;
42             }
43 
44             if(sum1 < sum2) R = mid;
45             else L = mid;
46         }
47         printf("%d\n", (int)mid);
48     }
49     return 0;
50 }

 

BestCoder Round #55 1001 Pyramid Split

标签:

原文地址:http://www.cnblogs.com/kiwibird/p/4803799.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!