1024: [SCOI2009]生日快樂
Time Limit: 1 Sec Memory Limit: 162 MB
Submit: 2998 Solved: 2183
[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
1 #include "bits/stdc++.h"
2 using namespace std;
3 typedef long long LL;
4 int X,Y,n;
5 double dfs(double x,double y,int m){
6 if (m==1) return max(x/y,y/x);
7 double i,an=1e9;
8 for (i=1.0;i<=m/2;i++){
9 double tx=x*i/m,ty=y*i/m;
10 an=min(an,max(dfs(tx,y,i),dfs(x-tx,y,m-i)));
11 an=min(an,max(dfs(x,ty,i),dfs(x,y-ty,m-i)));
12 }
13 return an;
14 }
15 int main(){
16 freopen ("cheer.in","r",stdin);freopen ("cheer.out","w",stdout);
17 int i,j;
18 scanf("%d%d%d",&X,&Y,&n);
19 printf("%.6lf",dfs(X,Y,n));
20 return 0;
21