Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

我的方法很搓,有好的方法么?

Posted by kikif at 2007-09-25 08:54:23 on Problem 1980
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator