Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
我的方法很搓,有好的方法么?#include<cstdio> #include<cmath> #include<iostream> #include<algorithm> using namespace std; const double zero=1e-12; int p,q,a,n; int sol; void dfs(int start,double sum,int cura,int left){ if(sum<-1*zero)return; if(sum<=zero&&sum>=-1*zero){ sol++; return; }else{ int i,j; for(i=start;left*(double)1/i>=sum-zero&&i*cura<=a+zero;i++){ dfs(i,sum-(double)1/i,i*cura,left-1); } } } int main(){ while(1){ scanf("%d%d%d%d",&p,&q,&a,&n); if(p==0&&q==0)break; sol=0; dfs(1,(double)p/q,1,n); printf("%d\n",sol); } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator