Bing碎冰 2022-01-29 19:50 采纳率: 83.3%
浏览 64
已结题

使用map容器出现错误


#include<bits/stdc++.h>
#define int long long
using namespace std;const int inf=1e5+10;
#define endl '\n'
struct node{
    int a,b,c;
};

// unordered_map<node,int>q;

int w(node root)
{
    
    // if(q.count(root))return q[root];
    if(root.c<=0||root.b<=0||root.a<=0){return 1;}
    if(root.c>20||root.b>20||root.a>20){root.c=20,root.b=20,root.a=20;}
    if(root.a<root.b&&root.b<root.c){
        int k=w({root.a,root.b,root.c-1})+w({root.a,root.b-1,root.c-1})+w({root.a,root.b-1,root.c});
        // q[root]=k;
        return k;
    }
    else{
        int k=w({root.a-1,root.b,root.c})+w({root.a-1,root.b-1,root.c})+w({root.a-1,root.b,root.c-1})-w({root.a-1,root.b-1,root.c-1});
        // q[root]=k;
        return k;
    }
}

signed main()
{
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    node root;

    while (cin>>root.a>>root.b>>root.c,!(root.c==-1&&root.b==-1&&root.a==-1))
    {
        node copy=root;
        int ans=w(root);
        printf("w(%lld, %lld, %lld) = %lld\n",copy.a,copy.b,copy.c,ans);
    }

    return 0;
}

报错放这

[Error] use of deleted function 'std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map() [with _Key = node; _Tp = long long int; _Hash = std::hash<node>; _Pred = std::equal_to<node>; _Alloc = std::allocator<std::pair<const node, long long int> >]'
[Error] use of deleted function 'std::hash<node>::hash()'

[Error] 'std::__hash_enum<_Tp, <anonymous> >::~__hash_enum() [with _Tp = node; bool <anonymous> = false]' is private within this context


(其实出现一堆东西指向编译器,但是太多就不复制了
类似 from D:/Dev-Cpp/MinGW32/include/c++/10.2.0/string
In file included from D:/Dev-Cpp/MinGW32/include/c++/10.2.0/bits/basic_string.h)

问题应该是那四行注释掉的代码导致的

  • 写回答

2条回答 默认 最新

  • _GX_ 2022-01-29 22:04
    关注

    你需要提供针对node结构体类型的hash函数,比如下面这样的

    namespace std
    {
        template <>
        struct hash<node>
        {
            size_t operator()(const node &n)
            {
                size_t h1 = hash<int>()(n.a);
                size_t h2 = hash<int>()(n.b);
                size_t h3 = hash<int>()(n.c);
                return h1 ^ (h2 << 1) ^ (h3 << 2);
            }
        };
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 3月31日
  • 已采纳回答 3月23日
  • 创建了问题 1月29日

悬赏问题

  • ¥15 echarts动画效果失效的问题。官网下载的例子。
  • ¥60 许可证msc licensing软件报错显示已有相同版本软件,但是下一步显示无法读取日志目录。
  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥30 关于<main>标签页面跳转的问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加