小编Unb*_*und的帖子

将棋盘转换为位掩码

我正在尝试将矩阵棋盘转换为无符号长长的棋盘.如果该位置有硬币我更新相应的掩码.继承我的代码

    unsigned long long int mask = 0;
    cout<<mask<<endl;
    for(int i=0;i<8;++i)
        for(int j=0;j<8;++j){
            int pos = i*8+j;
            cin>>board[i][j];
            if(board[i][j] == 'P')
                mask|=(1<<pos);
    }
     for(int i=0;i<8;++i)
     {
        for(int j=0;j<8;++j)
        {
            int pos = i*8+j;
            if(mask&(1<<pos))
                cout<<1;
            else
                cout<<0;

        }
        cout<<endl;
     }
Run Code Online (Sandbox Code Playgroud)

但是当我给出以下输入时

........
...P....
.....P..
...P....
........
........
P......P
.......P
Run Code Online (Sandbox Code Playgroud)

输出如下

00000000
00010000
10000101
00010001
00000000
00010000
10000101
00010001
Run Code Online (Sandbox Code Playgroud)

这显然是错的.但我似乎没有在这里发现任何错误.提前致谢.

c++ bit-manipulation

2
推荐指数
1
解决办法
100
查看次数

如何在C++中初始化类的priority_queue?

我正在尝试初始化priority_queue,这是代码

class stdnt{
    public:
        int indx;
        int c;
        int lvl;
    bool operator<(const stdnt &x)
    {
        return this->c > x.c;
    }
};
priority_queue<stdnt> pq;
Run Code Online (Sandbox Code Playgroud)

但它给了我传递const&discards限定符的错误.我还应该怎么做呢?

c++ priority-queue

0
推荐指数
1
解决办法
166
查看次数

标签 统计

c++ ×2

bit-manipulation ×1

priority-queue ×1