南华大学ACM个人连续第一场 E.Function
2013-07-08 10:45
453 查看
Problem E: Function
Time Limit: 1 Sec Memory Limit: 32 MBSubmit: 20 Solved: 16
[Submit][Status][Web
Board]
Description
Define a function f(n)=(f(n-1)+1)/f(n-2). You already got f(1) and f(2). Now, give you a number m, please find the value of f(m).Input
There are several test cases. Each case contains three integers indicating f(1), f(2) and m ( 1 <= f(1), f(2), m <= 1000,000,000).Output
For each case, please output the value of f(m), rounded to 6 decimal places.Sample Input
1 1 3Sample Output
2.0000其实这个题目是有规律的,当你一直算下去的时候,不管你给f(1),f(2),赋值为什么,每5个将循环一次。故这样就可以递归了,不会发生栈溢出,也不会超时,还要注意的就是变量的类型。
下面是我的代码:
#include<stdio.h>
double a,b;
long m;
double Re(int c)
{
if(c==1)
return a;
else if(c==2)
return b;
else if(c==0)
{
c=5;
return (double)(Re(c-1)+1)/Re(c-2);
}
else
return (double)(Re(c-1)+1)/Re(c-2);
}
int main(void)
{
while(scanf("%lf%lf%d",&a,&b,&m)==3)
{
double Result;
Result=Re(m%5);
printf("%.4lf\n",Result);
}
return 0;
}
相关文章推荐
- 20130707 【南华大学 ACM】 新生赛第一场 【E.Function】
- 南华大学ACM第一场个人联系赛 A Eming
- 南华大学ACM 个人练习第一场 B.Arithmetic Progression
- 20130707 【南华大学 ACM】 新生赛第一场 【D.Brackets】
- 20130820 【南华大学 ACM】 个人选拔赛第二场 【A . BAKA】
- 南华大学暑假个人练习第一场 1006: Triangle
- 20130820 【南华大学 ACM】 个人选拔赛第二场 【C . DOBRI】
- 08-22成都大学ACM集训个人赛第一场解题报告
- 20130707 【南华大学 ACM】 新生赛第一场 【B.Arithmetic Progression】
- 20130707 【南华大学 ACM】 新生赛第一场 【A.Eming】
- 20130820 【南华大学 ACM】 个人选拔赛第二场 【B . SUME】
- 南华大学ACM个人练习 第二场 D: The mell hall
- 个人博客成立,ACM博客记录生涯开始
- Hdu 5350 MZL's munhaff function 2015ACM多校对抗赛第五场
- 湖南工业大学个人选拔赛第一场 解题报告
- 关于参加ACM-ICPC的 ACMer的 个人训练问题
- [ACM] POJ 1611 The Suspects (并查集,输出第i个人所在集合的总人数)
- 第八届山东省ACM大学生程序设计竞赛个人总结
- Pku acm 1579 Function Run Fun
- 我的第一场ACM比赛