nefu 667

http://acm.nefu.edu.cn/JudgeOnline/problemshow.php?problem_id=667

description

    Although Dreamone has been studying in USTC for nearly one year,he is missing the mates of swust all the time.Recently Dreamone has found the equation through which he can feel be with them immediately,then what is the mysterious equation?
Given a number x(-100<=x<=100) and a funciton f(x).
when x<0,f(x)=0
when 0<=x<1,f(x)=1
when 1<=x<=100,f(x)=f(x-20.07)+f(x-4.28)+f(x-20.10)+f(x-6.11)
Because 2007.4.28 is a special day for Dreamone,so is 2010.6.11!
Maybe f(x) will be very large,so only output the most right four numbers(omitting leading zero).For example,if f(x)=521314,just output 1314;if f(x)=20080906,just output 906;
if f(x)=306,just output 306.
Can you solve the simple problem? 
							

input

The first line,a integer T,representing T test cases blew.(T<=1000).
Then each line contains a number x(-100<=x<=100).
							

output

 For each number x,output the most right four numbers of f(x)(omitting leading zero).
							

sample_input

2
-1
2
							

sample_output

0
0
在递归时用个数组保存已经求出的值可以节省运行时间,在数据不是很厉害的情况下,会有运行时间上的天壤之别的。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
int T,vis[111111];
double x;
int f(double x){
    if(x<0) return 0;
    else if(x>=0&&x<1) return 1;
    else{
        int tmp=int(x*100+1e-10);
        if(vis[tmp]!=-1) return vis[tmp];
        else return vis[tmp]=(f(x-20.07)%10000+f(x-4.28)%10000+f(x-20.10)%10000+f(x-6.11)%10000)%10000;
    }
}
int main()
{
    memset(vis,-1,sizeof(vis));
    scanf("%d",&T);
    while(T--)
    {
        scanf("%lf",&x);
        if(x<0)
             printf("0\n");
        else if(x>=0&&x<1)
             printf("1\n");
        else 
             printf("%d\n",f(x)%10000);
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值