随笔分类 - 位运算
位运算
摘要:题目传送门 #include<bits/stdc++.h> using namespace std; typedef long long LL; const int N = 110; LL a[N]; int n; LL res; int main() { //录入进来,终止条件是CTRL+D wh
阅读全文
摘要:题目传送门 #include <bits/stdc++.h> using namespace std; typedef long long LL; int main() { //取第k位 LL x; cin >> x; //& 0x0000ffff 是清空了前十六位 //& 0xffff0000 是
阅读全文
摘要:题目传送门 #include <bits/stdc++.h> using namespace std; int x; //输入的每枝筷子的长度 int n; //筷子的总数 int ans;//奇数个,落单的长度是多少 int main() { //不加这两句优化,第一个测试点TLE ios::sy
阅读全文
摘要:阅读材料: https://blog.csdn.net/weixin_41183791/article/details/84886700 1.去掉最后一位 x>>1 2.在最后加一个0 x<<1 3.在最后加一个1 (x<<1)+1 4.把最后一位变成1 x|1 5.把最后一位变成0 (x|1)-1
阅读全文
摘要:题目: 位运算实例,已知一个正整数变量,对这个数的二进制数列进行下面的操作,依次使用位运算符号写出操作方式: 1)将最后一位的右边加上一个,例如变为 答:将左移一位,然后加,就是 2)将最后一位变为,例如或者$1
阅读全文