[bzoj1024][SCOI2009]生日快乐【暴力】

【题目链接】
  http://www.lydsy.com/JudgeOnline/problem.php?id=1024
【题解】
  暴力每一刀是横着切还是竖着切并枚举两侧的块数。
  复杂度分析:
    设 g[i]n=i 时的复杂度。
    于是有:
     g[i]=1 (i=1)
     g[i]=2j=1i1(g[j]+g[ij])+1 (i2)
     整理后得 g[i]=5i1
  所以复杂度为 O(5n)

/* --------------
    user Vanisher
    problem bzoj-1024
----------------*/
# include <bits/stdc++.h>
# define    ll      long long
# define    inf     0x3f3f3f3f
using namespace std;
int read(){
    int tmp=0, fh=1; char ch=getchar();
    while (ch<'0'||ch>'9'){if (ch=='-') fh=-1; ch=getchar();}
    while (ch>='0'&&ch<='9'){tmp=tmp*10+ch-'0'; ch=getchar();}
    return tmp*fh;
}
double solve(double x, double y, int k){
    if (x<y) swap(x,y);
    if (k==1) return x/y;
    double ans=inf;
    for (int i=1; i<k; i++){
        ans=min(ans,max(solve(x/k*i,y,i),solve(x/k*(k-i),y,k-i)));
        ans=min(ans,max(solve(x,y/k*i,i),solve(x,y/k*(k-i),k-i)));
    }
    return ans;
}
int main(){
    int x=read(), y=read(), n=read();
    printf("%.6lf\n",solve(x,y,n));
    return 0;
}
posted @ 2018-02-25 21:52  Vanisher  阅读(65)  评论(0编辑  收藏