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

    本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作。

    本文作者:ljh2000
    作者博客:http://www.cnblogs.com/ljh2000-jump/
    转载请注明出处,侵权必究,保留最终解释权!

     

    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

     

    正解:搜索

    解题报告:

      裸搜索题,直接搜索每次横着切还是竖着切,同时均分成多少块。因为每个人的面积相等,所以注意一下,切成两半后必须要保证两边分成的块数之比要等于面积之比,仔细想想就可以想通了。

     1 //It is made by ljh2000
     2 #include <iostream>
     3 #include <cstdlib>
     4 #include <cstring>
     5 #include <cstdio>
     6 #include <cmath>
     7 #include <algorithm>
     8 #include <ctime>
     9 #include <vector>
    10 #include <queue>
    11 #include <map>
    12 #include <set>
    13 #include <string>
    14 #include <stack>
    15 using namespace std;
    16 typedef long long LL;
    17 int X,Y,n;
    18 
    19 inline int getint(){
    20     int w=0,q=0; char c=getchar(); while((c<'0'||c>'9') && c!='-') c=getchar();
    21     if(c=='-') q=1,c=getchar(); while (c>='0'&&c<='9') w=w*10+c-'0',c=getchar(); return q?-w:w;
    22 }
    23 
    24 inline double dfs(int num,double x,double y){//需要分成num块,且矩形长宽分别为x,y
    25     if(num==1) return max(x,y)/min(x,y); double now=1e20,nowx,nowy;
    26     for(int i=1;i<=num/2;i++) {//枚举横着或者竖着分成i份
    27     nowx=x/num*i; nowy=y/num*i;//分成
    28     now=min(now,max(dfs(i,nowx,y),dfs(num-i,x-nowx,y)));
    29     now=min(now,max(dfs(i,x,nowy),dfs(num-i,x,y-nowy)));
    30     }
    31     return now;
    32 }
    33 
    34 inline void work(){
    35     X=getint(); Y=getint(); n=getint();
    36     printf("%.6lf",dfs(n,X,Y));
    37 }
    38 
    39 int main()
    40 {
    41     work();
    42     return 0;
    43 }
  • 相关阅读:
    mybatis中的配置文件的约束
    win10下PHP开发环境搭建
    装饰器的理解
    在iis上添加woff字体文件读取
    转发:使用sql命令查询视图中所有引用的基础表
    转:C4项目中验证用户登录一个特性就搞定
    转载:NSobject官方介绍
    thinkphp生命周期
    array_intersect_assoc — 带索引检查计算数组的交集
    array_flip — 交换数组中的键和值
  • 原文地址:https://www.cnblogs.com/ljh2000-jump/p/6063364.html
Copyright © 2011-2022 走看看