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

    1024: [SCOI2009]生日快乐

    Time Limit: 1 Sec  Memory Limit: 162 MB
    Submit: 3025  Solved: 2201
    [Submit][Status][Discuss]

    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

    析:竟然是一个搜索题,我都想成二分。。。,但是没想到有什么好的办法来实现判定。

    搜索,对每次切的位置都搜索,因为 n 比较小,所以是完全可以的。

    代码如下:

    #pragma comment(linker, "/STACK:1024000000,1024000000")
    #include <cstdio>
    #include <string>
    #include <cstdlib>
    #include <cmath>
    #include <iostream>
    #include <cstring>
    #include <set>
    #include <queue>
    #include <algorithm>
    #include <vector>
    #include <map>
    #include <cctype>
    #include <cmath>
    #include <stack>
    #include <sstream>
    #include <list>
    #include <assert.h>
    #include <bitset>
    #include <numeric>
    #define debug() puts("++++")
    #define gcd(a, b) __gcd(a, b)
    #define lson l,m,rt<<1
    #define rson m+1,r,rt<<1|1
    #define fi first
    #define se second
    #define pb push_back
    #define sqr(x) ((x)*(x))
    #define ms(a,b) memset(a, b, sizeof a)
    #define sz size()
    #define pu push_up
    #define pd push_down
    #define cl clear()
    //#define all 1,n,1
    #define FOR(i,x,n)  for(int i = (x); i < (n); ++i)
    #define freopenr freopen("in.txt", "r", stdin)
    #define freopenw freopen("out.txt", "w", stdout)
    using namespace std;
    
    typedef long long LL;
    typedef unsigned long long ULL;
    typedef pair<int, int> P;
    const int INF = 0x3f3f3f3f;
    const LL LNF = 1e17;
    const double inf = 1e20;
    const double PI = acos(-1.0);
    const double eps = 1e-8;
    const int maxn = 400 + 10;
    const int maxm = 3e5 + 10;
    const ULL mod = 3;
    const int dr[] = {-1, 0, 1, 0};
    const int dc[] = {0, -1, 0, 1};
    const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
    int n, m;
    const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    inline bool is_in(int r, int c) {
      return r >= 0 && r < n && c >= 0 && c < m;
    }
    
    double dfs(double r, double c, int n){
      if(n == 1)  return max(r, c) / min(r, c);
      double rx = r / n, cx = c / n;
      double ans = inf;
      for(int i = 1; i <= n / 2; ++i){
        ans = min(ans, max(dfs(rx * i, c, i), dfs(r - rx * i, c, n - i)));
        ans = min(ans, max(dfs(r, cx * i, i), dfs(r, c - cx * i, n - i)));
      }
      return ans;
    }
    
    int main(){
      int K;
      scanf("%d %d %d", &n, &m, &K);
      printf("%.6f
    ", dfs(n, m, K));
      return 0;
    }
    

      

  • 相关阅读:
    Linux Vim编辑器
    Linux sed 流编辑器
    Shell 编程 (变量和条件测试)
    Linux 下 Bash配置文件读取
    Linux 用户、权限
    Linux 指令(一)文件/目录操作
    Ubuntu 下安装 Swoole
    Mysql IN语句查询
    Mysql 查询优化
    Mysql 获取表属性
  • 原文地址:https://www.cnblogs.com/dwtfukgv/p/7822421.html
Copyright © 2011-2022 走看看