bzoj 1024 生日快乐
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1024
题解:
枚举切开的两块的面积比例,由于每个人分得的面积要相同,所以面积比例的分子、分母都应为整数,还要按横切和纵切两种情况分开深搜
1 #include<cstdio> 2 int n,m,k; 3 inline double max(double x,double y) 4 { 5 return x>y?x:y; 6 } 7 inline double min(double x,double y) 8 { 9 return x<y?x:y; 10 } 11 double dfs(double x,double y,int dep) 12 { 13 if(dep==1)return max(x/y,y/x); 14 double ans=2147483647; 15 for(int i=1;i<=(dep>>1);i++) 16 { 17 double xx=x*i/dep,yy=y*i/dep; 18 ans=min(ans,max(dfs(xx,y,i),dfs(x-xx,y,dep-i)));//纵切 19 ans=min(ans,max(dfs(x,yy,i),dfs(x,y-yy,dep-i)));//横切 20 } 21 return ans; 22 } 23 int main() 24 { 25 scanf("%d%d%d",&n,&m,&k); 26 printf("%.6lf",dfs(n,m,k)); 27 return 0; 28 }