惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Hacker News: Ask HN
Hacker News: Ask HN
N
News and Events Feed by Topic
Forbes - Security
Forbes - Security
The Last Watchdog
The Last Watchdog
TaoSecurity Blog
TaoSecurity Blog
Schneier on Security
Schneier on Security
SecWiki News
SecWiki News
V
Vulnerabilities – Threatpost
Project Zero
Project Zero
O
OpenAI News
W
WeLiveSecurity
Security Archives - TechRepublic
Security Archives - TechRepublic
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
H
Hacker News: Front Page
Cisco Talos Blog
Cisco Talos Blog
Spread Privacy
Spread Privacy
Help Net Security
Help Net Security
P
Privacy & Cybersecurity Law Blog
K
Kaspersky official blog
S
Security @ Cisco Blogs
Latest news
Latest news
AWS News Blog
AWS News Blog
U
Unit 42
Martin Fowler
Martin Fowler
阮一峰的网络日志
阮一峰的网络日志
S
Secure Thoughts
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Know Your Adversary
Know Your Adversary
Scott Helme
Scott Helme
博客园 - 司徒正美
B
Blog RSS Feed
C
Check Point Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
D
Docker
Google Online Security Blog
Google Online Security Blog
Jina AI
Jina AI
aimingoo的专栏
aimingoo的专栏
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Last Week in AI
Last Week in AI
月光博客
月光博客
C
CXSECURITY Database RSS Feed - CXSecurity.com
S
SegmentFault 最新的问题
NISL@THU
NISL@THU
T
The Blog of Author Tim Ferriss
C
Cisco Blogs
Attack and Defense Labs
Attack and Defense Labs
小众软件
小众软件

博客园 - wasd

pear安装步骤 linux定时任务的设置 C语言字符串拆分,打开关闭文件 - wasd - 博客园 js-tips 用optgroup 禁用select中的option方法 - wasd - 博客园 DB2常用语句记录 addslashes、get_magic_quotes_gpc函数、stripslashes函数(转来记录一下) - wasd - 博客园 Linux 强制卸载软件 - wasd - 博客园 Setup locally visual host - wasd B:X星球的身份证系统 B:有道搜索框 B:有道饭团 A:另类的异或 CakePHP支持DB2 PHP 的变量 - wasd - 博客园 DB2 SQLSTATE 消息异常 JDBC中Preparedstatement使用小结 及JDBC插入数据后获得Last insert ID 并行计算简介 PB3编译adobe的例子photoviewer时错误处理
C:Sibonacci - wasd - 博客园
wasd · 2010-05-28 · via 博客园 - wasd

 描述

菲波那切数列可以用下列的式子表示:
f(1)=1
f(2)=1
f(n)=f(n-1)+f(n-2) (n>=3)

现在我们根据这个规则定义另一种数列 命名为"辛波那切数列", 它是这样定义的:
s(x)=0 (x<0)
s(x)=1 (0<=x<1)
s(x)=s(x-1)+s(x-3.14) (x>=1)

现在需要计算出s(x) MOD 1000000007的值。

输入
第一行有一个正整数T表示有T组测试数据。
接下来T行,每行包含一个数x。
其中 T<=10000, -1000.0<=x<=1000.0
输出
有T行,依次输出每组数据的结果。
样例输入
3
-1
0.667
3.15
样例输出
0
1
2

不知道对不对,没来得及提交 

C++版

 1 #include "iostream.h"
 2 #include <map>
 3 #include<time.h>
 4 using namespace std;
 5 
 6 map<double,int> haTable;
 7 int Sibonacci(double n)
 8 {
 9         if(n<0)return 0;
10         else if(n<3.14)return 1;
11         else {
12             int a = 0;
13             int b = 0;
14             map<double,int>::iterator iter;
15             iter = haTable.find(n-1);
16             if(iter!=haTable.end())
17                 a = (int)iter->second;
18             else a = Sibonacci(n-1);
19             
20             iter = haTable.find(n-3.14);
21             if(iter!=haTable.end())
22                 b = (int)iter->second;
23             else b = Sibonacci(n-3.14);
24             
25             int temp = (a+b)%1000000007;
26             haTable.insert(map<double,int>::value_type(n,temp));
27             return temp;
28         }
29 }
30 int main()
31 {
32    clock_t start,finish;
33    start=clock();
34    cout<<Sibonacci(1000)<<endl;
35    finish=clock();
36    cout<<finish-start/CLOCKS_PER_SEC;
37 }

JAVA版

代码

    public static void main(String[] args) {
        
// TODO Auto-generated method stub
        long startTime=System.currentTimeMillis();
        Integer temp = Sibonacci(1000);
        
long endTime=System.currentTimeMillis(); //获取结束时间 
        System.out.println(temp);
        System.out.println("程序运行时间: "+(endTime-startTime)+"ms");  
    }
    
public static Hashtable<Double,Integer> haTable = new Hashtable<Double,Integer>();
    
    
public static Integer Sibonacci(double n)
    {
        
if(n<0)return 0;
        
else if(n<3.14)return 1;
        
else {
            Integer a = 0;
            Integer b = 0;
            
if(haTable.containsKey(n-1))
                a = haTable.get(n-1);
            
else a = Sibonacci(n-1);
            
            
if(haTable.containsKey(n-3.14))
                b = haTable.get(n-3.14);
            
else b = Sibonacci(n-3.14);
            
            Integer temp = (a+b)%1000000007;
            haTable.put(n,temp);
            
return temp;
        }
        
    }
}

前者要用时4937ms

后者要用时2875ms

莫非是java中的hashtable性能要强于STL中的map。

权当是抛砖引玉,希望高手指点。