C++ std::map 运行超出范围

标签 c++ dictionary

我正在解决 SPOJ 问题 FLIB我已经尝试使用这样的 map 来实现它 -

long long FiboSum(long long n) {
    if(n==1||n==0) return n;
    if(fiboDict.count(n)) return (long long) fiboDict.at(n);
    if(n%2==0) { 
        //calculate term -- value to that key
        fiboDict.insert(pair<long,long>(n,term));
    }
    else { 
        //calculate term
        fiboDict.insert(pair<long,long>(n,term));
    }
    return (long long) fiboDict.at(n);
}

fiboDict是 map ,但问题需要我计算 ( 0 <= n < 2^51)但是 KEY 值不能保持这么高的值,我得到了错误

terminate called after throwing an instance of 'std::out_of_range' what():  
map::at

我怎样才能让它拥有大的值(value)?或者如果有其他选择,请提出建议。

最佳答案

你为什么不制作 map :

pair<long long,long long>

然后呢?

关于C++ std::map 运行超出范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12416615/

相关文章:

c++ - x64 构建 : error MSB8013: This project doesn't contain the Configuration and Platform combination of Debug|Win32

c# - C# 的 ObservableDictionary

android - Kotlin 与 Android 中的 map

c - 哈希表单词在 C 中被覆盖

c++ - 为什么这个对话框打开后立即关闭?

c++ - boost 正则表达式分词器和换行符

C# 嵌套字典 - 字典中的字典返回错误(KeyNotFoundException)

c# - Umbraco 7 使用语言/字典

c++ - 调用 std::map operator[] 或插入时会发生什么

c++ - ‘->’ 的基操作数具有非指针类型