2307 - A easy problem!

通过次数

0

提交次数

0

时间限制 : 1 秒 内存限制 : 128 MB


<span style="line-height:1.5;"><span style="font-family:'Microsoft Yahei';font-size:14px;line-height:21px;background-color:#F5F5F5;">Define&nbsp;a&nbsp;function&nbsp;f(n)=(f(n-1)+1)/f(n-2).&nbsp;You&nbsp;already&nbsp;got&nbsp;f(1)&nbsp;and&nbsp;f(2).&nbsp;Now,&nbsp;give&nbsp;you&nbsp;a&nbsp;number&nbsp;m,&nbsp;please&nbsp;find&nbsp;the&nbsp;value&nbsp;of&nbsp;f(m).</span></span>

<br />

题目输入

There are several test cases. Each case contains three integers indicating f(1), f(2) and m ( 1 <= f(1), f(2), m <110,000,000).

题目输出


<span style="font-family:'Microsoft Yahei';font-size:14px;line-height:28px;background-color:#F5F5F5;">For&nbsp;each&nbsp;case,&nbsp;please&nbsp;output&nbsp;the&nbsp;value&nbsp;of&nbsp;f(m),&nbsp;rounded&nbsp;to&nbsp;6&nbsp;decimal&nbsp;places.</span>

输入/输出样例

输入格式

1 1 3
1 2 3
4 8 10

输出格式

2.000000
3.000000
0.625000

C语言解答

#include <stdio.h>
int main()
{
	int m,i,n;
	double f[11000];
	while (scanf("%lf %lf %d",&f[1],&f[2],&m)!=EOF)
	{
		for (i=3;i<=100;i++)
		{
			f[i]=(f[i-1]+1)/f[i-2];
			if (f[i]==f[2])
			{
				if (f[i-1]==f[1])
				{
					n=i-2;
					break;
				}
			}
		}
		m=m%n;
		if (m==0) printf("%.6lf\n",f[n]);
		else printf("%.6lf\n",f[m]);
	}
	return 0;
}

C++解答

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;

double ans[6];

int main()
{
	int m;
//	FILE *p,*fp,*f;
//	fp=fopen("E:\\1.out","at");
//	f=fopen("E:\\2.in","r");
//	int cnt=0;
	while(scanf("%lf%lf%d",&ans[1],&ans[2],&m)!=EOF)
	{
	//	cnt++;
		ans[3]=(ans[2]+1)/ans[1];
		ans[4]=(ans[1]+ans[2]+1)/(ans[1]*ans[2]);
		ans[0]=(ans[1]+1)/ans[2];
		char str[10000];
		sprintf(str,"%.6lf",ans[m%5]);
		puts(str);
	//	fprintf(fp,"%s\n",str);
	}
//	printf("%d\n",cnt);
	//fclose(f);
	//fclose(fp);
	return 0;
}