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 r语言神经网络自变量重要性分析
  • ¥15 基于双目测规则物体尺寸
  • ¥15 wegame打不开英雄联盟
  • ¥15 公司的电脑,win10系统自带远程协助,访问家里个人电脑,提示出现内部错误,各种常规的设置都已经尝试,感觉公司对此功能进行了限制(我们是集团公司)
  • ¥15 救!ENVI5.6深度学习初始化模型报错怎么办?
  • ¥30 eclipse开启服务后,网页无法打开
  • ¥30 雷达辐射源信号参考模型
  • ¥15 html+css+js如何实现这样子的效果?
  • ¥15 STM32单片机自主设计
  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢