# BZOJ1024: [SCOI2009]生日快乐

#include<bits/stdc++.h>
#define MP make_pair
#define xx first
#define yy second
using namespace std;
double a,b;
int n;
typedef pair<pair<double,double>,int> pa;
map<pa,pa>pre;
double dfs(double x,double y,int k)
{
if(k==1)
return max(x/y,y/x);
double ans=1e9;
for(int i=1;i<=k/2;++i)
{
double nx=x/k*i,ny=y/k*i;
double t=max(dfs(nx,y,i),dfs(x-nx,y,k-i));
if(t<ans)
{
ans=t;
pre[MP(MP(x,y),k)]=MP(MP(nx,y),i);
}
t=max(dfs(x,ny,i),dfs(x,y-ny,k-i));
if(t<ans)
{
ans=t;
pre[MP(MP(x,y),k)]=MP(MP(x,ny),i);
}
}
return ans;
}
void print(double x,double y,int k)
{
double na,nb;
int nn;
if(k<=1) return;
pa p=MP(MP(x,y),k);
na=pre[p].xx.xx;
nb=pre[p].xx.yy;
nn=pre[p].yy;
printf("%.2lf %.2lf %d\n",na,nb,nn);
print(na,nb,nn);
if(nb==y)
{
printf("%.2lf %.2lf %d\n",x-na,nb,k-nn);
print(x-na,nb,k-nn);
}
else
{
printf("%.2lf %.2lf %d\n",x,y-nb,k-nn);
print(na,y-nb,k-nn);
}
}
int main()
{
scanf("%lf%lf%d",&a,&b,&n);
printf("%.6lf\n",dfs(a,b,n));
print(a,b,n);
}

posted @ 2018-01-17 12:15  大奕哥&VANE  阅读(101)  评论(0编辑  收藏