zoukankan      html  css  js  c++  java
  • [BZOJ1024] [SCOI2009] 生日快乐 (搜索)

    Description

      windy的生日到了,为了庆祝生日,他的朋友们帮他买了一个边长分别为 X 和 Y 的矩形蛋糕。现在包括windy
    ,一共有 N 个人来分这块大蛋糕,要求每个人必须获得相同面积的蛋糕。windy主刀,每一切只能平行于一块蛋糕
    的一边(任意一边),并且必须把这块蛋糕切成两块。这样,要切成 N 块蛋糕,windy必须切 N-1 次。为了使得
    每块蛋糕看起来漂亮,我们要求 N块蛋糕的长边与短边的比值的最大值最小。你能帮助windy求出这个比值么?

    Input

      包含三个整数,X Y N。1 <= X,Y <= 10000 ; 1 <= N <= 10

    Output

      包含一个浮点数,保留6位小数。

    Sample Input

    5 5 5

    Sample Output

    1.800000

    HINT

    Source

    Solution

      $n$不大,并且对于指定长与宽的蛋糕,我们可以切的位置是有限个的,所以可以直接枚举切的位置进行搜索

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 
     4 double DFS(double x, double y, int b)
     5 {
     6     double ans = 1e8, l, r;
     7     if(x < y) swap(x, y);
     8     if(b == 1) return x / y;
     9     l = 0, r = x;
    10     for(int i = 1; i <= b >> 1; ++i)
    11     {
    12         l += x / b, r -= x / b;
    13         ans = min(ans, max(DFS(l, y, i), DFS(r, y, b - i)));
    14     }
    15     l = 0, r = y;
    16     for(int i = 1; i <= b >> 1; ++i)
    17     {
    18         l += y / b, r -= y / b;
    19         ans = min(ans, max(DFS(x, l, i), DFS(x, r, b - i)));
    20     }
    21     return ans;
    22 }
    23 
    24 int main()
    25 {
    26     double x, y;
    27     int n;
    28     scanf("%lf%lf%d", &x, &y, &n);
    29     printf("%.6f
    ", DFS(x, y, n));
    30     return 0;
    31 }
    View Code
  • 相关阅读:
    基于摸板匹配的目標跟蹤算法
    spoj 2713 Can you answer these queries IV
    zoj 3633 Alice's present
    hdu 3642 Get The Treasury
    poj 1195 Mobile phones
    poj 2760 End of Windless Days
    zoj 3540 Adding New Machine
    spoj 1716 Can you answer these queries III
    spoj 1043 Can you answer these queries I
    spoj 2916 Can you answer these queries V
  • 原文地址:https://www.cnblogs.com/CtrlCV/p/5622946.html
Copyright © 2011-2022 走看看